. Advertisement .
..3..
. Advertisement .
..4..
I get the error message:
*** Start Block ***
errno99: cannot assign requested address
Has anyone ever faced this problem? How to troubleshoot the “oserror errno 99 cannot assign requested address.” The problem appears when I try to operate the following program:
#server code
import select
import socket
import sys
backlog = 5
size = 1024
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("10.0.0.1",9999))
server.listen(backlog)
input = [server]
running = 1
while running:
inputready,outputready,exceptready = select.select(input,[],[])
for s in inputready:
if s == server:
client, address = server.accept()
input.append(client)
else:
l = s.recv(1024)
sys.stdout.write(l)
server.close()
#client code
import socket
import select
import sys
import time
while(1) :
s,addr=server1.accept()
data=int(s.recv(4))
s = socket.socket()
s.connect(("10.0.0.1",9999))
while (1):
f=open ("hello1.txt", "rb")
l = f.read(1024)
s.send(l)
l = f.read(1024)
time.sleep(5)
s.close()
The cause: It’s complaining about a problem with the IP address rather than the port.
When you bind
localhost
or127.0.0.1
, you can only connect to your service from local.You can’t bind
10.0.0.1
because it’s not yours; you can only bind IP addresses that belong to your computer.Solution: Making everything become basic and perhaps you would like to test things below:
This error will also be displayed if the Docker container is not actively serving the port.
If you request a local URL that isn’t served by a host that has no listening/bound port, you will get a
No connection could be made because the target machine actively refused it
error. If you create a container that binds the port but no server is running within it, requests to that port from localhost will be returned as:[Errno 99] Cannot assign requested address
(if called within the container),[Errno 0] Error
(if called outside the container).This error and the behavior described above can be reproduced as follows:
Create a dummy container ( Note: This will pull the Python image from if it is not available locally ).
For
[Errno 0] Error
, you will need to enter a Python Console on host.[Errno 99] Cannot assign requested address
will allow you to access a Python Console on the Container by calling:In either case, call:
I decided to treat these errors as
No connection could be made because the target machine actively refused it
equivalents rather than try to fix them – though please let me know if this is a bad idea.This one took me over a whole day to figure out. All resources and answers that I could find on
[Errno 99] Cannot assign requested address
pointed in the right direction: binding to an occupied port; connecting to an invalid address;sysctl
conflicts; docker network issues;TIME_WAIT
being wrong, and many other things. This answer is not a direct answer to your question, but it could be a common cause of the error that you are describing in the question.