I am trying to make a check for expired domain name with python-requests
.
import requests
try:
status = requests.head('http://wowsucherror')
except requests.ConnectionError as exc:
print(exc)
This code looks too generic. It produces the following output:
HTTPConnectionPool(host='wowsucherror', port=80): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))
What I'd like to do is to catch this DNS error only (like ERR_NAME_NOT_RESOLVED
in Chrome). As a last resort I can just do string matching, but maybe there is a better, more structured and forward compatible way of dealing with this error?
Ideally it should be some DNSError
extension to requests
.
UPDATE: The error on Linux is different.
HTTPConnectionPool(host='wowsucherror', port=80): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))
Reported bug to requests
-> urllib3
https://github.com/shazow/urllib3/issues/1003
UPDATE2: OS X also reports different error.
requests.exceptions.ConnectionError: HTTPConnectionPool(host='wowsucherror', port=80): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))