1
我有一個腳本,它可以獲得Internet上很多頁面的HTTP Header,並且使用Python中的httplib
。Httplib無法處理特定域名
我的問題是在specific domain(可能是其他人),httplib
引發異常,我不明白爲什麼。
>>> import httplib
>>> http = httplib.HTTPConnection('iswtc.la')
>>> http.request('GET', '/a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.6/httplib.py", line 951, in _send_request
self.endheaders()
File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
self._send_output()
File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
self.send(msg)
File "/usr/lib64/python2.6/httplib.py", line 739, in send
self.connect()
File "/usr/lib64/python2.6/httplib.py", line 720, in connect
self.timeout)
File "/usr/lib64/python2.6/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
什麼是這個特定領域不同,我該怎麼處理呢?
PS:這不是我的代碼,因爲這工作得很好:
>>> http = httplib.HTTPConnection('bit.ly')
>>> http.request('GET', '/a')
好吧,如果工作正常這是你的代碼,因爲它不起作用... – 2013-03-02 20:35:39
@IanCarroll你是什麼意思?我把這段代碼放在我的'python'控制檯中,我沒有問題。 – Arthur 2013-03-02 20:38:13