python - urllib.error.URLError: <urlopen error [Errno 11002] getaddrinfo failed>? -
so, code 4 lines. trying connect website, trying after irrelevant because error arised without other codes.
import urllib.request bs4 import beautifulsoup html=urllib.request.urlopen('http://python-data.dr-chuck.net/known_by_fikret.html').read() soup=beautifulsoup(html,'html.parser')
and error(succinctly summarized one):
for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [errno 11002] getaddrinfo failed during handling of above exception, exception occurred: urllib.error.urlerror: <urlopen error [errno 11002] getaddrinfo failed>
here have tried.
- i searched error returned "urlopen error [errno 11002]” on google , on stackoverflow, nothing helpful returned(in fact there not question on error 11002 asked).
- so try replace website argument(i.e. "http://python-data.dr-chuck.net/known_by_fikret.html" ) inside urlopen function website "http://www.pythonlearn.com/code/urllinks.py". , worked fine. no error comes up.
- so guess error must have particular website per se. website dynamic, mean content alter , change wholly different thing. have no more knowledge descibe saw.
and longer , full version of error:
traceback (most recent call last): file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 1240, in do_open h.request(req.get_method(), req.selector, req.data, headers) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\http\client.py", line 1083, in request self._send_request(method, url, body, headers) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\http\client.py", line 1128, in _send_request self.endheaders(body) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\http\client.py", line 1079, in endheaders self._send_output(message_body) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\http\client.py", line 911, in _send_output self.send(msg) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\http\client.py", line 854, in send self.connect() file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\http\client.py", line 826, in connect (self.host,self.port), self.timeout, self.source_address) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\socket.py", line 693, in create_connection res in getaddrinfo(host, port, 0, sock_stream): file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\socket.py", line 732, in getaddrinfo res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [errno 11002] getaddrinfo failed during handling of above exception, 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:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 162, in urlopen return opener.open(url, data, timeout) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 465, in open response = self._open(req, data) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 483, in _open '_open', req) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 443, in _call_chain result = func(*args) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 1268, in http_open return self.do_open(http.client.httpconnection, req) file "c:\users\administrator\appdata\local\programs\python\python35-32\lib\urllib\request.py", line 1242, in do_open raise urlerror(err) urllib.error.urlerror: <urlopen error [errno 11002] getaddrinfo failed>
this means either dns system not working correctly, or have use proxy on network , isn't defined correctly.
if need use proxy, set environment variable http_proxy
(and optionally, https_proxy
) correct configuration network. format http://proxy.example.com:80
; if proxy needs username , password, should pass in, this: http://username:password@proxy.example.com:80
.
for dns issues, try looking domain command line. open command prompt , type nslookup python-data.dr-chuck.net
, see if returns ip address.
Comments
Post a Comment