I am scraping a site using selenium in python, I get the desired results when I run the same script on windows, but in ubuntu 16.04 when I run the same script it throws error:
File "/usr/lib/python2.7/httplib.py", line 402, in_read_status
raise BadStatusLine(line)
BadStatusLine: ''
can anyone give me an idea why is this error raised?
Thanks :)
This error message...
File "/usr/lib/python2.7/httplib.py", line 402, in_read_status raise BadStatusLine(line) BadStatusLine
...implies that the BadStatusLine was raised as the server responded with a HTTP status code that we don’t understand.
exception httplib.BadStatusLine Python2.x/Python3.x
exception httplib.BadStatusLine is defined in Python2.x - httplib / Python3.x - http.client module and is subclass of HTTPException which is raised if a server responds with a HTTP status code that we don’t understand.
Reasons and Solutions
There can be many reason behind seeing the httplib.BadStatusLine exception. As per Why am I getting this error in python ? (httplib) some of the pottential reasons and solutions are:
- You may be trying to use
http://
instead of https://
- The URL string may be containing a trailing newline character. So make sure that your URL are stripped of any leading or trailing special characters.
- The Web Server may be down and Not Responding.
- The Server may be closing the connection before sending a valid response.
- Presence of
Content-Length
within the http header
can also create this exception.
- If the time interval between two requests are more than he configured time of
Keep-Alive timeout=n
.
- An easy solution would be to establish a new connection through
conn.connect()
before sending each request.