close

[Solved] socket.error:[errno 99] cannot assign requested address and namespace in python

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error socket.error:[errno 99] cannot assign requested address and namespace in python in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How socket.error:[errno 99] cannot assign requested address and namespace in python Error Occurs?

Today I get the following error socket.error:[errno 99] cannot assign requested address and namespace in python in python.

How To Solve socket.error:[errno 99] cannot assign requested address and namespace in python Error ?

  1. How To Solve socket.error:[errno 99] cannot assign requested address and namespace in python Error ?

    To Solve socket.error:[errno 99] cannot assign requested address and namespace in python Error when you bind localhost or 127.0.0.1, it means you can only connect to your service from local.

  2. socket.error:[errno 99] cannot assign requested address and namespace in python

    To Solve socket.error:[errno 99] cannot assign requested address and namespace in python Error when you bind localhost or 127.0.0.1, it means you can only connect to your service from local.

Solution 1


This error will also appear if you try to connect to an exposed port from within a Docker container, when nothing is actively serving the port.

On a host where nothing is listening/bound to that port you’d get a No connection could be made because the target machine actively refused it error instead when making a request to a local URL that is not served, eg: localhost:5000. However, if you start a container that binds to the port, but there is no server running inside of it actually serving the port, any requests to that port on localhost will result in:

  • [Errno 99] Cannot assign requested address (if called from within the container), or
  • [Errno 0] Error (if called from outside of the container).

You can reproduce this error and the behaviour described above as follows:

Start a dummy container (note: this will pull the python image if not found locally):

docker run --name serv1 -p 5000:5000 -dit python

Then for [Errno 0] Error enter a Python console on host, while for [Errno 99] Cannot assign requested address access a Python console on the container by calling:

docker exec -it -u 0 serv1 python

And then in either case call:

import urllib.request
urllib.request.urlopen('https://localhost:5000')

I concluded with treating either of these errors as equivalent to No connection could be made because the target machine actively refused it rather than trying to fix their cause – although please advise if that’s a bad idea.

Solution 2

when you bind localhost or 127.0.0.1, it means you can only connect to your service from local.

you cannot bind 10.0.0.1 because it not belong to you, you can only bind ip owned by your computer

you can bind 0.0.0.0 because it means all ip on your computer, so any ip can connect to your service if they can connect to any of your ip

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read