且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WSGI 中的 httplib 无法发送请求错误

更新时间:2022-10-31 17:55:37

当您将 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.