When I use httplib for my OAUTH in Python, I always get “CannotSendRequest” and then "

。_饼干妹妹 提交于 2019-12-24 08:19:39

问题


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.             self._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.


回答1:


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.



来源:https://stackoverflow.com/questions/2310143/when-i-use-httplib-for-my-oauth-in-python-i-always-get-cannotsendrequest-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!