making socket.getaddrinfo use cached dns

Nobody nobody at nowhere.com
Fri Jul 8 02:18:35 EDT 2011


On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth <widebandwidth at gmail.com> wrote:

>> I use cached dns lookups with pdnsd on my ubuntu machine to speed up
>> web access as regular lookups can take 15-30 seconds. However, python's
>> mechanize and urllib etc use socket.getaddrinfo, which seems not to be
>> using dns cacheing or taking a long time because of ipv6 lookups. In
>> either case, I subsequent access to the same site to be fast and not
>> require lengthy calls to getaddrinfo. How can I get python to correctly
>> use cached dns lookups and ipv4 only (at least in those cases where it
>> is appropriate).

To only query IPv4 addresses, pass socket.AF_INET as the third argument
(family) to socket.getaddrinfo(). The default is AF_UNSPEC (= 0), which
will return both IPv4 and IPv6 addresses.




More information about the Python-list mailing list