连接中止.', BadStatusLine("''",) 在服务器上? [英] Connection aborted.', BadStatusLine("''",) on server?

查看:64
本文介绍了连接中止.', BadStatusLine("''",) 在服务器上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码从网络获取图像:

I use the following code to get image from network:

path = 'http://domgvozdem.ru/images/ustanovka-kondicionera-svoimi-rukami.jpg'
def exists(path):
    r = requests.head(path)
    return r.status_code == requests.codes.ok

我有一个错误:

发生主要错误:('Connection aborted.', BadStatusLine("''",)) 发生主要错误:('Connection aborted.', BadStatusLine("''",))

Main error has occurred: ('Connection aborted.', BadStatusLine("''",)) Main error has occurred: ('Connection aborted.', BadStatusLine("''",))

如何解决?是不是被主机屏蔽了?

How to fix that? It it blocked by hoster?

推荐答案

当您的 Python 客户端收到空响应(标头/body)时,您会收到此错误.

You get this error when your Python client receives an empty response (header /body).

顺便说一句,较新的 Python 版本会抛出不同的异常,当服务器断开连接或网络问题时可能会发生这种情况.

BTW newer Python version will throw a different Exception, It can happen when the server disconnects the connections, or a network issue.

就我而言,我们花了几周时间尝试重现它,直到找到主要原因,我们有一个 Python 应用程序向 Nginx 负载均衡器后面的服务发送请求,

In my case, we spent some weeks trying to reproduce it until we found the main cause, We have a Python application sending requests to a service behind Nginx loadbalancer,

我们发现当客户端超过默认的 Nginx 配置 client_header_timeout/client_body_timeout (60 sec) 时,Nginx 会断开连接,这是 Nginx 等待来自客户端的额外数据包的时间.

We found that Nginx disconnects the connection when the client exceeded the default Nginx configurations client_header_timeout / client_body_timeout (60 sec), it's the time that Nginx will wait for additional data packet from the client.

你可以参考这个参考http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_timeout

当我们的应用程序加载 CPU 处理时,连接已建立,但标头和请求正文在传输之前有很长的延迟,超过 82 秒.

When our application is loaded with CPU processing, connections are established but header and request body have a long delay until transmitted, over 82 seconds.

所以 Nginx 关闭连接并返回重置数据包(记录的 tcpdump 带有空的 body 和 headers),正式它应该返回状态码 408,这不会发生.

So Nginx closes the connection and returns reset packet (recorded tcpdump with empty body and headers), officially it should return status code 408, which is not happening.

我们通过将两个参数的 client_header_timeout/client_body_timeout 增加到 180 秒来解决这个问题:

We solved it by increasing the client_header_timeout / client_body_timeout to 180s for both params:

server {
..
client_body_timeout 180s;
client_header_timeout 180s;
}

这篇关于连接中止.', BadStatusLine("''",) 在服务器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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