Skip to content Skip to sidebar Skip to footer

"TypeError: A Float Is Required" Occurred When Using Urllib2

I was following the twitter API documentation of issuing application-only requests. Error occurred when doing Step 2: Obtain a bearer token. I'm not familiar with the details of th

Solution 1:

The urlopen function uses this format: urllib2.urlopen(url[, data][, timeout])

In your code you are giving the headers to urlopen as the timeout value which causes you to get the TypeError.

The headers should be added by creating the request with the urllib2.Request() function. For example:

req = urllib2.Request('https://api.twitter.com/oauth2/token', urllib.urlencode(data), headers)
resp = urllib2.urlopen(req)

Post a Comment for ""TypeError: A Float Is Required" Occurred When Using Urllib2"