Error: getaddrinfo failed

Hello!
I am new on working with ELK and when I run my code I get the following error :

2019-08-09 15:43:04,526 CRITICAL: N/A<urllib3.connection.HTTPConnection object at 0x000002916B9EC780>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed<urllib3.connection.HTTPConnection object at 0x000002916B9EC780>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

I have set up an environment with elasticsearch 7.3 and kibana 7.3 on my computer, locally , using as a connection: "hosts": "localhost:9200".
Elasticsearch is up and running in the shell before starting to run the code.
If I try to use as a connection one of the three nodes in my cluster, it works. But I need to make it work also locally.

Any ideas why I am getting this error? Thank you a lot!