简体   繁体   中英

Python requests library throws badstatusline exception only on Linux

I get 'badstatusline' exception, for one of the websites that I am trying to fetch. Problem shows only on Linux, but everything works OK on Windows. Tested on:

  1. Windows 7 64bit, Python 2.6.x 32 bit -> OK
  2. Windows XP SP3, Python 2.7.3 -> OK
  3. Xubuntu 12.10, Python 2.7.3 -> badstatusline
  4. 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:

HTTP request sent, awaiting response... No data received.

Edit1:

Exception: HTTPSConnectionPool(host='somesite.com', port=443): Max retries exceeded with url: Caused by class 'httplib.BadStatusLine': '')

This is from 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. And again, it works like charm on Win7 and Win XP.

Edit2: curl on linux reports "Empty reply from server" curl on windows reports the same - "Empty reply from server"

Have you attempted to verify that you're receiving valid HTML? If not, I'd try printing out what the request is receiving and making sure that it conforms to standards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM