Overriding the System Resolver

Sometimes it can be useful to make all of Python use dnspython’s resolver rather than the default functionality in the socket module. Dnspython can redefine the methods in the socket module to point at its own code, and it can also restore them back to the regular Python defaults.


Override the system resolver routines in the socket module with versions which use dnspython’s resolver.

This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system’s resolver settings (e.g. /etc/resolv.conf).

The resolver to use may be specified; if it’s not, the default resolver will be used.

resolver, a dns.resolver.Resolver or None, the resolver to use.


Undo the effects of prior override_system_resolver().