简体   繁体   English

Python请求库仅在Linux上引发badstatusline异常

[英]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: 经过测试:

  1. Windows 7 64bit, Python 2.6.x 32 bit -> OK Windows 7 64位,Python 2.6.x 32位->确定
  2. Windows XP SP3, Python 2.7.3 -> OK Windows XP SP3,Python 2.7.3->确定
  3. Xubuntu 12.10, Python 2.7.3 -> badstatusline Xubuntu 12.10,Python 2.7.3-> badstatusline
  4. Ubuntu 12.04 LTS, Python 2.7.3 -> badstatusline Ubuntu 12.04 LTS,Python 2.7.3-> badstatusline

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.

相关问题 为什么python请求抛出这个BadStatusLine异常 - Why is python requests throwing this BadStatusLine exception Python requests.exception.ConnectionError:连接中止“BadStatusLine” - Python requests.exception.ConnectionError: connection aborted “BadStatusLine” Python:httplib和请求问题; https似乎会导致重定向,然后BadStatusLine异常 - Python: Issues with httplib & requests; https seems to cause a redirect then BadStatusLine exception BadStatusLine使用Python,请求时出错 - BadStatusLine Error in using Python, Requests 当xml大小增加时,Python请求XML API异常ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Requests XML API Exception ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) when xml size increases Python http.client仅在1个系统上在完全有效的HTTP上抛出BadStatusLine。 Wireshark已验证 - Python http.client throws BadStatusLine on a perfectly valid HTTP, on 1 system only. Wireshark verified 某些DELETE请求上的Python BadStatusLine错误 - Python BadStatusLine error on certain DELETE requests Python子进程阻塞并获取BadStatusLine异常 - Python subprocess blocking and getting BadStatusLine exception 通过Python库request-oauthlib将OAuth与Google结合使用会引发MissingCodeError异常 - Using OAuth with Google thru the Python library requests-oauthlib throws the exception MissingCodeError Python请求库异常处理 - Python requests library Exception handling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM