how to force python httplib library to use only A requests

后端 未结 2 1298
臣服心动
臣服心动 2020-12-18 14:59

The problem is that urllib using httplib is querying for AAAA records.

I would like to avoid that. Is there a nice way to do that?

>>> impor         


        
相关标签:
2条回答
  • 2020-12-18 15:48

    Look here: how-do-i-resolve-an-srv-record-in-python

    Once you resolved the correct A ip, use it in your request, instead of the dns.

    0 讨论(0)
  • The correct answer is:

    http://docs.python.org/library/socket.html

    The Python socket library is using the following:

    socket.socket([family[, type[, proto]]]) Create a new socket using the given address family, socket type and protocol number. The address family should be AF_INET (the default), AF_INET6 or AF_UNIX. The socket type should be SOCK_STREAM (the default), SOCK_DGRAM or perhaps one of the other SOCK_ constants. The protocol number is usually zero and may be omitted in that case.

    /* Supported address families. */
    #define AF_UNSPEC       0
    #define AF_INET         2       /* Internet IP Protocol         */
    #define AF_INET6        10      /* IP version 6                 */
    

    By default it is using 0 and if you call it with 2 it will query only for A records.

    Remember caching the resolv results in your app IS A REALLY BAD IDEA. Never do it!

    0 讨论(0)
提交回复
热议问题