close

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

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error socket.gaierror: [Errno -2] Name or service not known | Python in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

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

Today I get the following error socket.gaierror: [Errno -2] Name or service not known | Python in python.

How To Solve socket.gaierror: [Errno -2] Name or service not known | Python Error ?

  1. How To Solve socket.gaierror: [Errno -2] Name or service not known | Python Error ?

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

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

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

Solution 1

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.

Solution 2

An possible solution is capture socket.gaioerror with OSError

Documentation info:

exception socket.gaierror

A subclass of OSError, this exception is raised for address-related errors by getaddrinfo() and getnameinfo(). The accompanying value is a pair (error, string) representing an error returned by a library call. string represents the description of error, as returned by the gai_strerror() C function. The numeric error value will match one of the EAI_* constants defined in this module.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read