How I fixed Python OSError: [Errno 99] Cannot assign requested address


When binding a socket, you see an error message like

Traceback (most recent call last):
  File "", line 91, in <module>
    server = start_server(loop, ('', 8080))
  File "", line 86, in start_server
    transport, server = loop.run_until_complete(t)
  File "/usr/lib/python3.8/asyncio/", line 616, in run_until_complete
    return future.result()
  File "/usr/lib/python3.8/asyncio/", line 1332, in create_datagram_endpoint
    raise exceptions[0]
  File "/usr/lib/python3.8/asyncio/", line 1316, in create_datagram_endpoint
OSError: [Errno 99] Cannot assign requested address


In my case, the issue was that I was trying to bind the specific IP address but the computer running the script did not have said IP address configured on any interface.

server = start_server(loop, ('', 8080))

so I needed to change the bind IP address to either to listen to ANY IP address or I needed to change to the IP address of the host computer I am running the script on.

Docker container [Errno 99] Cannot assign requested address

Note that for Docker containers, either you need to run them in network_mode: host to use the host’s network systemd, or you need to bind to the container’s IP address. You can not bind to the host’s IP address from the contaienr unless using network_mode: host! But you can forward the ports from the host, binding to a specific IP address.