socket.gaierror: [Errno -2] Name or service not known
Python couldn't resolve the hostname
Seen in Python socket, requests, urllib3 (NameResolutionError), httpx, aiohttp
DNS lookup for the hostname failed, so Python never opened a connection (Errno 8 on macOS, 11001 on Windows).
Common causes
- A typo in the hostname, or a scheme or path left in it (for example "https://example.com" passed as a host).
- The DNS record does not exist.
- An internal name that only resolves on a VPN or inside another network.
- A container or service name that is not on the same Docker network.
How to fix it
- Print the host the code actually uses and check its spelling.
- Look up the name to confirm the record exists.
- Check the VPN or container network that should resolve the name.
Got a different message? Paste it into the error explainer.
Related errors
- socket.gaierror: [Errno -3] Temporary failure in name resolution · Python couldn't reach a DNS resolver
- java.net.UnknownHostException · Java couldn't resolve the hostname
- dial tcp: lookup example.com: no such host · Go couldn't resolve the hostname
- No such host is known · Windows couldn't resolve the hostname
- php_network_getaddresses: getaddrinfo failed · PHP couldn't resolve the hostname
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed · Python couldn't verify the server's certificate
- certificate verify failed: Hostname mismatch, certificate is not valid for · The certificate doesn't cover this hostname
- Max retries exceeded with url · requests gave up connecting to the URL
- requests.exceptions.ConnectTimeout · Python couldn't open the connection in time
- requests.exceptions.ReadTimeout · The server took too long to respond
- ConnectionRefusedError: [Errno 111] Connection refused · Nothing is listening on that port
- http.client.RemoteDisconnected: Remote end closed connection without response · The server closed the connection without replying