urllib.error.URLError: <urlopen error [Errno 11002] getaddrinfo failed>? [英] urllib.error.URLError: <urlopen error [Errno 11002] getaddrinfo failed>?
问题描述
所以,我的代码只有 4 行.我正在尝试连接到一个网站,之后我尝试做的事情无关紧要,因为在没有其他代码的情况下出现了错误.
So, My code is only 4 lines. I am trying to connect to a website, what I am trying to do after that is irrelevant because the error arised without the other codes.
import urllib.request
from bs4 import BeautifulSoup
html=urllib.request.urlopen('http://python-data.dr-chuck.net/known_by_Fikret.html').read()
soup=BeautifulSoup(html,'html.parser')
和错误(简要总结一个):
and the error(succinctly summarized one):
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11002] getaddrinfo failed
During handling of the above exception, another exception occurred:
urllib.error.URLError: <urlopen error [Errno 11002] getaddrinfo failed>
这是我尝试过的.
- 我在谷歌上搜索了错误返回urlopen error [Errno 11002]",特别是在 stackoverflow 上,没有返回任何有用的信息(事实上,这个错误 11002 被问到的问题并不多).
- 然后我尝试替换网站参数(即http://python-data.dr-chuck.net/known_by_Fikret.html" ) 与另一个网站 "http://www.pythonlearn.com/code/urllinks.py".它工作得很好.没有错误出现.
- 所以我想这个错误一定与这个特定的网站本身有关.该网站有点动态,我的意思是它的内容会改变并变成另一个完全不同的东西.但我没有更多的知识,只能描述我所看到的.
- I searched for the Error returned "urlopen error [Errno 11002]" on google and especially on stackoverflow, nothing helpful was returned(In fact there are not much question on this error 11002 was asked).
- So Then I try to replace the website argument(i.e. "http://python-data.dr-chuck.net/known_by_Fikret.html" ) inside the urlopen function with another website "http://www.pythonlearn.com/code/urllinks.py". And it worked just fine. No error comes up.
- So I guess this error must have something to do with this particular website per se. The website is somewhat dynamic, by which I mean its content will alter and change into another wholly different thing. But I have no more knowledge than just to descibe what I saw.
以及更长的完整版错误:
and the longer and full version of error:
Traceback (most recent call last):
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 1240, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libhttpclient.py", line 1083, in request
self._send_request(method, url, body, headers)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libhttpclient.py", line 1128, in _send_request
self.endheaders(body)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libhttpclient.py", line 1079, in endheaders
self._send_output(message_body)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libhttpclient.py", line 911, in _send_output
self.send(msg)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libhttpclient.py", line 854, in send
self.connect()
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libhttpclient.py", line 826, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libsocket.py", line 693, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32libsocket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11002] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/baiduyundownload/Tempo/Active/Python/Python Examples/Fileanalysis11111.py", line 4, in <module>
html=urllib.request.urlopen('http://python-data.dr-chuck.net/known_by_Fikret.html').read()
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 465, in open
response = self._open(req, data)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 483, in _open
'_open', req)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 443, in _call_chain
result = func(*args)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 1268, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython35-32liburllib
equest.py", line 1242, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11002] getaddrinfo failed>
推荐答案
这意味着要么您的 DNS 系统工作不正常,要么您必须在您的网络上使用代理但未正确定义.
This means that either your DNS system is not working correctly, or you have to use a proxy on your network and it isn't defined correctly.
如果您需要使用代理,请将环境变量 HTTP_PROXY
(以及可选的 HTTPS_PROXY
)设置为您网络的正确配置.格式为http://proxy.example.com:80
;如果您的代理需要用户名和密码,您应该将其传入,如下所示:http://username:password@proxy.example.com:80
.
If you need to use a proxy, set the environment variable HTTP_PROXY
(and optionally, HTTPS_PROXY
) to the correct configuration for your network. The format is http://proxy.example.com:80
; if your proxy needs a username and password, you should pass it in, like this: http://username:password@proxy.example.com:80
.
对于 DNS 问题,请尝试从命令行查找域.打开命令提示符并输入 nslookup python-data.dr-chuck.net
并查看它是否会返回一个 IP 地址.
For DNS issues, try looking up the domain from the command line. Open a command prompt and type nslookup python-data.dr-chuck.net
and see if it returns to you an IP address.
这篇关于urllib.error.URLError: <urlopen error [Errno 11002] getaddrinfo failed>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!