DNS lookup error exception
See original GitHub issueI am using requests
to check domain status for k8s.io
domains (https://github.com/kubernetes/k8s.io/pull/30) and I can’t find a good way to check for DNS lookup error like ERR_NAME_NOT_RESOLVED
in Chrome. Exceptions output seems platform specific:
Traceback (most recent call last):
File "check.py", line 11, in <module>
status = requests.head('http://' + site)
File "C:\Python27\lib\site-packages\requests\api.py", line 93, in head
return request('head', url, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 437, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='jenkins.k8s.io', port=80):
Max retries exceeded with url: / (Caused by
NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at
0x029E43B0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))
So I was redirected here from https://github.com/kennethreitz/requests/issues/3630#issuecomment-255031285 to see if urllib3
could expose more fine-grained DNSLookupError exception and maybe remove MaxRetryError wrapper.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:15 (10 by maintainers)
Top Results From Across the Web
How To Fix DNS Lookup Failed Error In Google Chrome
Clear DNS Cache On Your Computer To Fix DNS Lookup Failed Error · Click on Start logo. · Type cmd.exe in the Run...
Read more >How to Fix A DNS Lookup Error - Compuchenna
How to Fix A DNS Lookup Error · Check Physical Connections · Flush Your DNS Server Cache · Renew Your IP · Rebuild...
Read more >How to Troubleshoot DNS Errors (Timeouts, Codes & More)
Learn how to troubleshoot DNS errors such as timeouts, codes, and more. Answer the question of what is a DNS error and why...
Read more >Python Examples of dns.exception.DNSException
This page shows Python examples of dns.exception.DNSException.
Read more >DNS Lookup failed - Error with all browsers - Stack Overflow
Windows maintains a DNS cache and if an IP address changes before the cache has refreshed you'll get a site not found error....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, so.
We’re certainly not going to remove the
MaxRetryError
: that’s not a winner. But we can probably be more clear about the specific error by hoisting thegetaddrinfo
call on line 75 ofurllib3/util/connection.py
out of thefor
statement and shoving it in atry...except
that raises an appropriate urllib3 exception.That would at least give you a specific exception to try to haul out.
MaxRetryError
has areason
attribute which you can use to fetch the underlying exception, so you can from that point take the exception.Note, however, that this change will take a while to propagate into a released version of Requests. In the interim, you may find it more helpful to check for DNS errors by simply calling
socket.getaddrinfo
yourself before making the request.Right! (Well technically there are other possible errors: see “Return Value” at https://linux.die.net/man/3/gai_strerror.) This was the original request from psf/requests#3630 which can now be solved. Well, or at least if could if it was not in feature freeze. Sorry for the five years delay.
I’m not sure how useful that would be, but in any case that would be a different issue.