from urllib3.util import connection
_orig_create_connection = connection.create_connection
defpatched_create_connection(address, *args, **kwargs):"""Wrap urllib3's create_connection to resolve the name elsewhere"""# resolve hostname to an ip address; use your own# resolver here, as otherwise the system resolver will be used.
host, port = address
hostname = your_dns_resolver(host)
return _orig_create_connection((hostname, port), *args, **kwargs)
connection.create_connection = patched_create_connection