Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this error in python ? (httplib)

Tags:

python

http

if theurl.startswith("http://"): theurl = theurl[7:]     head = theurl[:theurl.find('/')]     tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status)  http://www.garageband.com/mp3cat/.UZCKbS6N4qk/01_Saraenglish.mp3 Traceback (most recent call last):   File "check_data_404.py", line 51, in <module>     run()   File "check_data_404.py", line 35, in run     res = conn.getresponse()   File "/usr/lib/python2.6/httplib.py", line 950, in getresponse     response.begin()   File "/usr/lib/python2.6/httplib.py", line 390, in begin     version, status, reason = self._read_status()   File "/usr/lib/python2.6/httplib.py", line 354, in _read_status     raise BadStatusLine(line) httplib.BadStatusLine 

Does anyone know what "Bad Status Line" is?

Edit: I tried this for many servers, and many URL's and I still get this error?

like image 383
TIMEX Avatar asked Nov 20 '09 02:11

TIMEX


1 Answers

From the documentation for httplib (Python 2) (called http.client in Python 3):

exception httplib.BadStatusLine: (exception http.client.BadStatusLine:)

A subclass of HTTPException.

Raised if a server responds with an HTTP status code that we don’t understand.

I ran the same code and did not receive an error:

>>> theurl = 'http://www.garageband.com/mp3cat/.UZCKbS6N4qk/01_Saraenglish.mp3' >>> if theurl.startswith("http://"): ...     theurl = theurl[7:] ...     head = theurl[:theurl.find('/')] ...     tail = theurl[theurl.find('/'):] ...  >>> head 'www.garageband.com' >>> tail '/mp3cat/.UZCKbS6N4qk/01_Saraenglish.mp3' >>> response_code = 0 >>> import httplib >>> conn = httplib.HTTPConnection(head) >>> conn.request("HEAD", tail) >>> res = conn.getresponse() >>> res.status 302 >>> response_code = int(res.status) 

I guess just double-check everything and try again?

like image 108
jathanism Avatar answered Sep 22 '22 21:09

jathanism