[英]Python requests library throws badstatusline exception only on Linux
I get 'badstatusline'
exception, for one of the websites that I am trying to fetch. 对于我要获取
'badstatusline'
其中一个网站,我收到'badstatusline'
例外。 Problem shows only on Linux, but everything works OK on Windows. 问题仅在Linux上显示,但在Windows上一切正常。 Tested on:
经过测试:
This is my code: 这是我的代码:
import requests
url = 'https://somewebsite.com'
try:
r = requests.get(url, verify=False)
except Exception, e:
print e
I have tried adding custom headers to the request, but it didn't help. 我尝试将自定义标头添加到请求中,但没有帮助。 What could be the problem?
可能是什么问题呢?
I have tried with wget, but I receive the following response: 我尝试使用wget,但收到以下响应:
HTTP request sent, awaiting response... No data received. HTTP请求已发送,正在等待响应...未收到数据。
Edit1: 编辑1:
Exception: HTTPSConnectionPool(host='somesite.com', port=443): Max retries exceeded with url: Caused by class 'httplib.BadStatusLine': '') 例外:HTTPSConnectionPool(host ='somesite.com',port = 443):url超过最大重试次数:由类'httplib.BadStatusLine':引起)
This is from httplib: 这来自httplib:
def _read_status(self):
# Initialize with Simple-Response defaults
line = self.fp.readline()
if self.debuglevel > 0:
print "reply:", repr(line)
if not line:
# Presumably, the server closed the connection before
# sending a valid response.
raise BadStatusLine(line)
I can bypass this, but that is not the solution. 我可以绕过这个,但这不是解决方案。 Solution would be if my request could act more like FF and reach the data anyway.
解决的办法是,如果我的请求更像FF,并且仍然可以到达数据。 And again, it works like charm on Win7 and Win XP.
再次,它在Win7和Win XP上就像魅力一样工作。
Edit2: curl on linux reports "Empty reply from server" curl on windows reports the same - "Empty reply from server" Edit2: Linux上的curl报告“来自服务器的空回复” Windows上的curl报告相同-“来自服务器的空回复”
Have you attempted to verify that you're receiving valid HTML? 您是否尝试过验证自己是否收到了有效的HTML? If not, I'd try printing out what the request is receiving and making sure that it conforms to standards
如果没有,我将尝试打印出请求的内容并确保其符合标准
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.