WSGI 中的 httplib 无法发送请求错误 [英] httplib CannotSendRequest error in WSGI

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

问题描述

我在 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).

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

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

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

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()

无法发送请求

推荐答案

当您将 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 无法发送请求错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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