question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DNS lookup error exception

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Lukasacommented, Oct 20, 2016

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 the getaddrinfo call on line 75 of urllib3/util/connection.py out of the for statement and shoving it in a try...except that raises an appropriate urllib3 exception.

That would at least give you a specific exception to try to haul out. MaxRetryError has a reason 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.

0reactions
pquentincommented, Aug 12, 2021

So NameResolutionError only triggers when there is no DNS record, right? And if DNS server is not responding, a TimeoutError is raised. Is that it?

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 wonder if urllib3 should support detecting if DNS server is down vs main server is down.

I’m not sure how useful that would be, but in any case that would be a different issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found