WSGI中的httplib CannotSendRequest错误 [英] httplib CannotSendRequest error in WSGI

查看:108
本文介绍了WSGI中的httplib CannotSendRequest错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django中使用了两个不同的python oauth库,以便通过twitter进行身份验证.该安装程序是通过WSGI在apache上进行的.当我重新启动服务器时,一切正常运行约10分钟,然后httplib似乎锁定了(请参阅以下错误).

I've used two different python oauth libraries with Django to authenticate with twitter. The setup is on apache with WSGI. When I restart the server everything works great for about 10 minutes and then the httplib seems to lock up (see the following error).

我只运行1个进程和1个WSGI线程,但这似乎没有什么区别.

I'm running only 1 process and 1 thread of WSGI but that seems to make no difference.

我无法弄清楚为什么它会锁定并给出此CannotSendRequest错误.在这个令人沮丧的问题上,我花了很多时间.任何可能的提示/建议将不胜感激.

I cannot figure out why it's locking up and giving this CannotSendRequest error. I've spent a lot of hours on this frustrating problem. Any hints/suggestions of what it could be would be greatly appreciated.

File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 92, in get_response
  response = callback(request, *callback_args, **callback_kwargs)

File "mypath/auth/decorators.py", line 9, in decorated
  return f(*args, **kwargs)

File "mypath/auth/views.py", line 30, in login
  token = get_unauthorized_token()

File "/root/storm/eye/auth/utils.py", line 49, in get_unauthorized_token
  return oauth.OAuthToken.from_string(oauth_response(req))

File "mypath/auth/utils.py", line 41, in oauth_response
  connection().request(req.http_method, req.to_url())

File "/usr/lib/python2.5/httplib.py", line 866, in request
  self._send_request(method, url, body, headers)

File "/usr/lib/python2.5/httplib.py", line 883, in _send_request
  self.putrequest(method, url, **skips)

File "/usr/lib/python2.5/httplib.py", line 770, in putrequest
  raise CannotSendRequest()

CannotSendRequest

CannotSendRequest

推荐答案

当您为新请求重用httplib.HTTP对象而没有为先前请求调用getresponse()方法时,会引发此异常.在此错误之前,可能还有其他错误使连接处于断开状态.解决问题的最简单可靠的方法是为每个请求创建新的连接,而不是重用它.当然,它会慢一些,但是我认为让您在单进程和单线程中运行应用程序不是问题.

This exception is raised when you reuse httplib.HTTP object for new request while you havn't called its getresponse() method for previous request. Probably there was some other error before this one that left connection in broken state. The simplest reliable way to fix the problem is creating new connection for each request, not reusing it. Sure, it will be a bit slower, but I think it's not an issue having you are running application in single process and single thread.

这篇关于WSGI中的httplib CannotSendRequest错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆