When I use httplib for my OAUTH in Python, I always get "CannotSendRequest" and then "
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/home/ea/ea/hell/life/views.py" in linkedin_auth
274. token = oauth_linkedin.get_unauthorised_request_token()
File "/home/ea/ea/hell/life/oauth_linkedin.py" in get_unauthorised_request_token
52. resp = fetch_response(oauth_request, connection)
File "/home/ea/ea/hell/life/oauth_linkedin.py" in fetch_response
42. connection.request(oauth_request.http_method,url)
File "/usr/lib/python2.6/httplib.py" in request
874. 开发者_如何学Goself._send_request(method, url, body, headers)
File "/usr/lib/python2.6/httplib.py" in _send_request
891. self.putrequest(method, url, **skips)
File "/usr/lib/python2.6/httplib.py" in putrequest
778. raise CannotSendRequest()
Exception Type: CannotSendRequest at /linkedin/auth
Exception Value:
And then, sometimes I get: BadStatusLine error instead of this.
It's pretty random. I don't know when or why they happen. It happens more frequently when I'm running the Django development server (and less frequently when in APACHE2...but it still happens at random times). When this error happens, I have to restart my server.
Apparently (from here) this happens if you try to reuse an httplib.HTTP
object which had not been fully used. Maybe a connection pool in the library you're using, and an exception getting thrown during the request processing? Suggestion is to create new connection objects every time.
精彩评论