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

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("https://stackoverflow.com/")]
...     tail = theurl[theurl.find("https://stackoverflow.com/"):]
... 
>>> 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?

Leave a Comment