Why am I Getting Socket.Gaierror: [Errno -2] from Python Httplib

socket.gaierror: [Errno -2] Name or service not known

sys.argv[0] is not what you think it is. sys.argv[0] is the name of the program or script. The script's first argument is sys.argv[1].

socket.gaierror: [Errno -2] Name or service not known | Python

socket.gaierror: [Errno -2] Name or service not known means that the name resolution is failing for the given domain (api.github.com).

Name resolution (DNS in the usual notion) can fail for various reasons. As you have disconnected the internet, the reason is pretty obvious (Name or service not known).

gai (GetAddressInfo) is actually used by glibc to perform the name resolutions, it's part of glibc (and socket is using that as you can imagine). You can also actually configure it in /etc/gai.conf.

gai error at /home [Errno -2] Name or service not known

You've misunderstood the documentation to httplib. The parameter to instantiate the HTTPSConnection is just the hostname. You then pass the actual path as the second param to request. So:

connection = httplib.HTTPSConnection('rpxnow.com')
connection.request('POST', '/api/v2/auth_info', params)


Related Topics



Leave a reply



Submit