为什么我在python中收到此错误? (httplib的)

问题描述:

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

有谁知道Bad Status Line是什么?

Does anyone know what "Bad Status Line" is?

编辑:我为很多服务器尝试了这个,很多网址和我仍然会收到此错误?

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

来自 httplib(Python 2)的文档(称为 Python 3中的http.client ):


例外 httplib。 BadStatusLine :( 例外 http.client。 BadStatusLine :)

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


HTTPException

如果服务器以我们不理解的HTTP状态代码响应,则引发。

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?