Skip to content
MtrXTools

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

  1. Print the host the code actually uses and check its spelling.
  2. Look up the name to confirm the record exists.
  3. Check the VPN or container network that should resolve the name.
Look up the name

Got a different message? Paste it into the error explainer.

Related errors

All 32 Languages & runtimes errors