Httplib无法处理特定域

时间:2013-03-02 20:34:07

标签: python http exception dns

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

我的问题出现在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')

1 个答案:

答案 0 :(得分: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