Tips To Fix “socket.gaierror: [errno 8] nodename nor servname provided, or not known problem”

Python is the core of programming that created a stir in the world of programming since its inception. Even today, it is so in demand that we get updates that come in the news if we keep checking it. It has given the freedom to programmers to develop the application they are planning with ease. The libraries also make the functions simpler. In short, Python is a short word with a whole programming process inside it. When working with Python programs, it is evident to have errors. You may encounter “socket.gaierror: [errno 8] nodename nor servname provided, or not known problem” error.

The socket.gaierror is an error that happens during the search for an IP address. It is an exception that you get. No need to worry when this error message shows up as we help you solve it. Before jumping directly to the solution, let’s go step-by-step and figure out how you get the error warning

How the error warning pops up

The error message shows up when you try to update your mac to macOS Sierra. This is what you get in return

import socket
 Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
 gaierror: [Errno 8] nodename nor servname provided, or not known

Now that you know how you can land up in the error message, check out the ways to fix it

Ways To Handle the Error “socket.gaierror: [errno 8] nodename nor servname provided, or not known problem”

The cause of the error is that no hostname is added to the program. When you miss the IP address of the hostname that is used for local DNS config, then you end up with the error warning. It needs to be fixed in order to get rid of the error. Have a look at the solutions

Solution 1 – Convert your code

To fix the error warning, you need to convert your program code like this

import socket

An alternative to use when using the computer that is specified in /etc/hosts. Have a look at the solution to handle the exception ET02282-MAC.local localhost

Use ‘ET02282-MAC.local’ in the connection. And, it resolves the error.

Solution 2 – Remove protocol

Another solution to fix the error is to remove the protocol. In most cases, URLS are added with a protocol that causes the error. Have a look at the example

With protocol the cause error

companies_list = ['', '']

Remove the protocol

companies_list = ['www.', 'www.']

Solution 3 – macOS Catalina user

If you are using the 10.15.7 version of macOS Catalina, you can solve the error using the below code

import socket

if env == "PRODUCTION":
    ip_address = socket.gethostbyname(socket.gethostname())
    ip_address = ""


In this post, we shed light on the solution to help you get through the error “socket.gaierror: [errno 8] nodename nor servname provided, or not known problem”. You can try any of the solutions as per your project’s need.

I wish you luck!

Reference Source:

Leave a Reply

Your email address will not be published. Required fields are marked *