[Solved] Python Error: socket.gaierror : [errno 11004] getaddrinfo failed error

Because we are doing some web data set processing, we need to resolve the domain name and organize Ip, so we use

First, read the domain name from the previously processed domain name dataset
Secondly, loop through them one by one
Do the exception handling


But the results are obviously not as good as they should be, but when you manually put a single domain name in and resolve it, there is no problem.


I think the problem is a newline at the end of server_name.

So I need to remove the ‘\n’

To explain, there are two ways to remove line breaks here.
Method 1: With .sprip(‘\n’)
Method 2: [:-1] (because the line break is always in the last character)
I hope this will help and solve the problem smoothly and instantly.

def get_dns():
    domains = DataDispose.get_domain_list()
    for domain in domains:
            myaddr = socket.getaddrinfo(domain[:-1], 'http')
        except Exception as e:


Read More: