exceptions.TypeError an integer is required

jakecjacobson jakecjacobson at gmail.com
Mon Jul 27 11:44:40 EDT 2009


On Jul 24, 3:11 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 24 Jul 2009 11:24:58 -0700, jakecjacobson wrote:
> > I am trying to do a post to a REST API over HTTPS and requires the
> > script to pass a cert to the server.  I am getting "exceptions.TypeError
> > an integer is required" error and can't find the reason.  I commenting
> > out the lines of code, it is happening on the connection.request() line.
> >  Here is the problem code.  Would love some help if possible.
>
> Please post the traceback that you get.
>
> My guess is that you are passing a string instead of an integer, probably
> for the port.
>
> [...]
>
> >    except:
> >            print sys.exc_type, sys.exc_value
>
> As a general rule, a bare except of that fashion is bad practice. Unless
> you can explain why it is normally bad practice, *and* why your case is
> an exception (no pun intended) to the rule "never use bare except
> clauses", I suggest you either:
>
> * replace "except:" with "except Exception:" instead.
>
> * better still, re-write the entire try block as:
>
>     try:
>         [code goes here]
>     finally:
>         connection.close()
>
> and use the Python error-reporting mechanism instead of defeating it.
>
> --
> Steven

Steven,

You are quite correct in your statements.  My goal was not to make
great code but something that I could quickly test.  My assumption was
that the httplib.HTTPSConnection() would do the cast to int for me.
As soon as I cast it to an int, I was able to get past that issue.

Still not able to post because I am getting a bad cert error.

Jake Jacobson



More information about the Python-list mailing list