gpt4 book ai didi

python - Httplib 无法处理特定域

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:10:44 28 4
gpt4 key购买 nike

我有一个脚本,它使用 Python 中的 httplib 获取互联网上很多页面的 HTTP header 。

我的问题是关于 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')

最佳答案

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

关于python - Httplib 无法处理特定域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15179157/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com