1

httplib我有一个脚本,它使用Python获取 Internet 上许多页面的 HTTP 标头。

我的问题在特定域(可能还有其他域)上,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')
4

1 回答 1

1

bit.ly存在,而不存在iswtc.la

$ nslookup bit.ly

Non-authoritative answer:
Name:   bit.ly
Address: 69.58.188.39
Name:   bit.ly
Address: 69.58.188.40


$ nslookup iswtc.la

** server can't find iswtc.la: NXDOMAIN
于 2013-03-02T20:38:12.173 回答