How I fixed Python OSError: [Errno 99] Cannot assign requested address
When binding a socket, you see an error message like
In my case, the issue was that I was trying to bind the specific IP address 192.168.1.100 but the computer running the script did not have said IP address configured on any interface.
so I needed to change the bind IP address to either 0.0.0.0 to listen to ANY IP address or I needed to change 192.168.1.100 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.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow
- 3D printing (44)
- Algorithms (6)
- Allgemein (88)
- Android (4)
- Arduino (5)
- Audio/Video (28)
- Bioinformatics (23)
- Calculators (28)
- cloud-init (1)
- CoreOS (16)
- Docker (129)
- Kubernetes (11)
- Portainer (3)
- Cryptography (11)
- Data science (11)
- Documentation (1)
- Economics (1)
- Compliance (8)
- Components (27)
- Arduino (87)
- ESP8266/ESP32 (148)
- FreeRTOS (14)
- MicroPython (15)
- PlatformIO (151)
- Raspberry Pi (58)
- Teensy (10)
- Home-Assistant (10)
- LinuxCNC (6)
- LumenPnP (3)
- Medical devices (6)
- Optoelectronics (1)
- Teardown (1)
- ImageMagick (2)
- InvenTree (11)
- Wordpress (31)
- Generators (4)
- Leaflet (1)
- OpenStreetMap (4)
- Geoinformatics (5)
- Hardware (7)
- Alpine Linux (30)
- systemd (16)
- Machine learning (2)
- Mathematics (10)
- FreePBX (13)
- MikroTik (59)
- OpenWRT (13)
- Synology (1)
- Tactical RMM (1)
- Headscale (15)
- OpenVPN (2)
- Wireguard (24)
- ZeroTier (9)
- Nextcloud (11)
- OpenCASCADE (33)
- Patents (1)
- Performance (4)
- Physics (7)
- GCC errors (51)
- Haskell (8)
- Angular (30)
- NodeJS (57)
- Octave (13)
- Cartopy (15)
- OpenPyXL (7)
- pandas (52)
- Paramiko (4)
- skyfield (6)
- Typescript (22)
- Subversion (2)
- Security (5)
- Statistics (8)
- ElasticSearch (34)
- MongoDB (9)
- Jupyter (2)
- OpenCV (10)
- Pyppeteer (13)
- Traefik (17)
- Virtualization (18)
- TechOverflow (2)
- PowerShell (4)
Python – OSError: [Errno 99] Cannot assign requested address – py
python sockets ubuntu
I just copied this code for a client/server example:
http://www.bogotobogo.com/python/python_network_programming_server_client.php
and when I run the code I get this error:
Best Solution
Replace host = socket.gethostname() with host = '127.0.0.1' and it should work.
Hope this wil help :)
Related Solutions
Python: socket.error connection refused in unix [errno 111].
You have multiple problems here. First, by using connect on the server end, you're telling the operating system that you will only be communicating with IP address "192.168.67.42" port 5000. That is probably not what you intended. (A server usually talks to whatever client wants to talk to it.)
Second, by not specifying SOCK_DGRAM in your client, you're getting the default socket type, which is SOCK_STREAM . That means your client is trying to connect to your server on TCP port 80 -- not UDP port 80 (the two namespaces are totally separate).
For a UDP "session", both sides need an IP address and a port number. If you do not bind a port specifically, the operating system will choose one for you quasi-randomly. In order to link up client and server, they must agree on at least one of those.
So a typical UDP server will bind to a well-known port (presumably you intended 5000 for that purpose). Then the client can connect to the server at that port. The code would look something like this ( sans error handling):
Server side:
The client is close to what you have, but you should send some data from the client to the server first so that the server knows your address:
Note that because you have used connect on the client side, you've permanently specified your peer's address and don't need to use recvfrom and sendto .
Related Question

OSError: [Errno 99] Cannot assign requested address #2714
I am using dgl==0.4.3 My server is initialized but my client can not connect to the server.
Note that they are running in the same machine.
Error message: starting server…
KVServer listen at 0.0.0.0:8523
model init loaded pretrained relation embeddings. dim: 768 Traceback (most recent call last): File “/home/ktfp768/CoLAKE/pretrain/run_pretrain.py”, line 266, in train() File “/home/ktfp768/CoLAKE/pretrain/run_pretrain.py”, line 198, in train cache_dir=PYTORCH_PRETRAINED_BERT_CACHE + ‘/dist_{}’.format(args.local_rank)) File “/home/ktfp768/test/lib/python3.6/site-packages/transformers/modeling_utils.py”, line 655, in from_pretrained model = cls(config, *model_args, **model_kwargs) File “…/pretrain/model.py”, line 20, in init self.ent_embeddings = LargeEmbedding(ip_config, emb_name, ent_lr, num_ent) File “…/pretrain/large_emb.py”, line 185, in init self.client = EmbClient(server_namebook) File “…/pretrain/large_emb.py”, line 99, in init super(). init (server_namebook, queue_size, net_type) File “/home/ktfp768/test/lib/python3.6/site-packages/dgl/contrib/dis_kvstore.py”, line 588, in init self._machine_id = self._get_local_machine_id() File “/home/ktfp768/test/lib/python3.6/site-packages/dgl/contrib/dis_kvstore.py”, line 981, in _get_local_machine_id if ip in self._local_ip4_addr_list(): File “/home/ktfp768/test/lib/python3.6/site-packages/dgl/contrib/dis_kvstore.py”, line 999, in _local_ip4_addr_list struct.pack(‘256s’, name[:15].encode(“UTF-8”)))[20:24]) OSError: [Errno 99] Cannot assign requested address Exception ignored in: <bound method KVClient. del of <pretrain.large_emb.EmbClient object at 0x7f8edc30c780>> Traceback (most recent call last): File “/home/ktfp768/test/lib/python3.6/site-packages/dgl/contrib/dis_kvstore.py”, line 604, in del _finalize_sender(self._sender) AttributeError: ‘EmbClient’ object has no attribute ‘_sender’ Exception ignored in: <bound method LargeEmbedding. del of LargeEmbedding()> Traceback (most recent call last): File “…/pretrain/large_emb.py”, line 204, in del self.client.shut_down() File “/home/ktfp768/test/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 779, in getattr type(self). name , name)) torch.nn.modules.module.ModuleAttributeError: ‘LargeEmbedding’ object has no attribute ‘client’ Traceback (most recent call last): File “/opt/scp/software/Python/3.6.3-foss-2017a/lib/python3.6/runpy.py”, line 193, in _run_module_as_main “ main ”, mod_spec) File “/opt/scp/software/Python/3.6.3-foss-2017a/lib/python3.6/runpy.py”, line 85, in _run_code exec(code, run_globals) File “/home/ktfp768/test/lib/python3.6/site-packages/torch/distributed/launch.py”, line 260, in main() File “/home/ktfp768/test/lib/python3.6/site-packages/torch/distributed/launch.py”, line 256, in main cmd=cmd) subprocess.CalledProcessError: Command ‘[’/home/ktfp768/test/bin/python’, ‘-u’, ‘/home/ktfp768/CoLAKE/pretrain/run_pretrain.py’, ‘–local_rank=0’, ‘–name’, ‘CoLAKE’, ‘–data_prop’, ‘1.0’, ‘–batch_size’, ‘2048’, ‘–lr’, ‘1e-4’, ‘–ent_lr’, ‘1e-4’, ‘–epoch’, ‘1’, ‘–grad_accumulation’, ‘16’, ‘–save_model’, ‘–emb_name’, ‘entity_emb’, ‘–n_negs’, ‘200’, ‘–beta’, ‘0.98’]’ returned non-zero exit status 1.
The error is OSError: [Errno 99] Cannot assign requested address. Can you verify which ip address the client is trying to connect?
It is trying to connect to ip of local machine: 127.0.0.1 with an available port
Can the error due to: linux - Get IP address from python - Stack Overflow I am not sure what is the network status of your colab machine.
This issue is resolved: AttributeError: 'EmbClient' object has no attribute 'set_partition_book' · Issue #7 · txsun1997/CoLAKE · GitHub . One should modify _get_local_machine_id() in KVClient with DGL 0.4.3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
OSError: [Errno 99] Cannot assign requested address
I installed the latest prodigy (prodigy-0.5.0-cp35.cp36-cp35m.cp36m-linux_x86_64.whl)
I then ran the following commands from https://prodi.gy/docs/workflow-text-classification:
I get the following error:
I was able to work around this by changing the default host in prodigy.json to 127.0.0.1:
Some additional debugging of waitress directly:
Some information about my environment:

The default host is localhost – and considering it’s in your /etc/hosts and you can ping it without problems, I’m really not sure what’s going wrong here… We’re also not doing anything “clever” or especially custom here – Prodigy is mostly just serving the app using waitress with a pretty standard configuration.
On the other hand, network stuff isn’t our strongest skill, so we’re open for suggestions here. Maybe we should consider using 127.0.0.1 instead of localhost then? Adding a note to the docs early on would probably make sense, too. (Even if we get the localhost stuff to work properly, some users may still have their hosts configured differently, so having a little reminder could be nice.)
So I was poking at this further and I noticed I’m only able to get this working when I use host “0.0.0.0”. With “127.0.0.1” the app starts without crashing but I can’t connect to it from a browser.

Here’s my Dockerfile:
And the commands I’m running to build and run the container:
The Dockerfile requires that you have the linux prodigy wheel and a prodigy.json in the CWD
Here’s my updated prodigy.json:
Update: I talked with my local docker guru and we’re convinced this is a quirk of docker networking. Obviously when running these tools in production you’ll either need to bind to 0.0.0.0 or setup some kind of gateway like nginx so it probably can’t hurt to mention something about this caveat in the docs.
Thanks for the awesome tool!
Thanks for following up! Definitely good to have this in the docs.
In hindsight I suppose it makes some sense that within the container, localhost doesn’t point out to the outside world.
Thanks, this is really helpful and good to know! I’ve added a “Using Prodigy with Docker” section to the configuration docs that mentions this, link to this thread for more details and also suggests setting "host": "0.0.0.0" as a possible solution for other environments and setups that produce a similar error.
Would it be possible to add an example Dockerfile to the Prodigy documentation. It wasn’t trivial to set up Prodigy in Docker for someone new to Docker, and I spent a couple hours trying to get it to work.
Before I found this post I got Prodigy working in Docker using the “python:3.7-slim” base image, in contrast to the “python:stretch” base image used in the Dockerfile in the previous post. The “python:3.7-slim” base image doesn’t include gcc therefore I had to install gcc in order to install the prodigy*.whl, and then uninstall gcc to save space (see link ). In fact I also had to add g++ because I got another error (see link ). In the end this looks a bit messy but it leads to a Docker image which is less than half the size (733 MB as opposed to 1.51 GB). So in case anyone cares about the size of their Docker image then I thought I’d post my solution here. Here’s the Dockerfile I used.
I hope this helps,
Ressurrecting this thread to attach this https://pythonspeed.com/articles/docker-connection-refused/ which helped me understand when having faced this same problem.
Search code, repositories, users, issues, pull requests...
Provide feedback.
We read every piece of feedback, and take your input very seriously.

Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
- Notifications
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: OSError: [Errno 99] Cannot assign requested address #605
bytos commented Jul 11, 2021 • edited
felipediel commented Oct 17, 2021
- 👍 1 reaction
Sorry, something went wrong.
bytos commented Oct 27, 2021 • edited
No branches or pull requests

Cannot Assign Requested Address: A Step-By-Step Guide
- Recent Posts

- Error in fix.by(by.y, Y) : ‘By’ Must Specify a Uniquely Valid Column - November 20, 2023
- Python Import Errors: A Discussion on Causes and Solutions - November 19, 2023
- Yowsup Stream Code 503 Error: Tackling the Challenge - November 19, 2023

Considering this, we found several debugging procedures to help you overcome assign requested inconsistency without compromising other functions and processes.
You will also learn how to recreate and display the mistake before applying the solutions, which is critical with complex applications and programs.
JUMP TO TOPIC
– Connecting to the DBD Using a Non-standard Linear Policy
– pointing to the subdomain with several tcp ports, – modifying the tcp buckets and kernel parameters, why is the cannot assign requested address bug happening.
The requested address that the system cannot assign a bug usually happens when the binding hostname does not have a local network interface. However, the mistake can occur when connecting to the DDB using a non-standard linear policy for all cross-account accesses. Both instances compromise the main commands.
Therefore, this error log is almost inevitable when the binding hostname or IP lacks a local network interface. This inconsistency forces your system or application to display assign requested address warnings indicating the failed procedures, which should help you overcome it and apply the debugging techniques.
In addition, the lack of a local network interface when binding the hostname or IP confuses other processes and commands. As a result, we will help you remake and reproduce the broken exception using real-life examples and scripts, which may or may not be similar to your document or file.
On the contrary, launching a non-standard linear policy for all cross-account accesses when connecting to the DDB is another common cause. For instance, the system throws an error log when executing the read query on the DDB table under heavy load, although it raises no warnings when using average load.
The document also sets the necessary timeouts on the DDB client with increased max connections for the STS client configurations. Still, let us reproduce the error log using standard examples and scripts before listing the possible solutions and debugging techniques.

Although the warnings in your system differ, the error’s root and cause remain unchanged.
The following example provides the complete broken syntax:
As a result, the system returns a stack trace explaining the cause and providing information on the exact failed commands . We will omit the broken code snippet, although some lines could resemble the elements and functions in your document.
On the flip side, the system should not experience a bug when the program is under low load, which is standard with simple applications and programs. However, this is one of the many instances of confusing your application and launching the error log.
Another typical instance of confusing your program and displaying the error log points to the subdomain with several TCP ports.
Although this procedure sounds straightforward and only renders several inputs, the application cannot access the domain from the browser without HTTPS protection . As a result, we will exemplify the sudo processes before listing the flawed visual output.
You can learn more about the subdomain with several TCP ports below:
Lastly, we will complete the invalid procedure listing the stack trace, as shown in the following example:
The application terminates the systems and fails further procedures . However, the solutions and debugging techniques work for all documents.
How to Fix the Assign Requested Address That Does Not Work?
You can fix the assigned requested address that does not function by replacing the short-lived connections to reduce the TCP connections. In addition, you can modify the TCP buckets and kernel parameters of the ECS that host the client. The solutions do not affect primary and secondary procedures.
You can learn more about the code in the following example:
Although this repairs the failed instance and fixes the connections, the method is only complete after replacing the connections. This step establishes the persistent connections and uses them over short-lived inputs.
The following example provides the necessary code snippet:
The error log should no longer compromise or obliterate your program, especially with complex applications and projects. Still, the alternative solution suggests modifying the ECS’s TCP buckets and kernel parameters.

The following list provides the solutions:
- Locate the ECS instance for the client.
- Run the following command line to view the parameters: sysctl net.ipv4.tcp_max_tw_buckets net.ipv4.ip_local_port_range
- The system returns the output and confirms the procedures.
- Input the following command line to complete the solution and repair your document: sysctl -w net.ipv4.tcp_max_tw_buckets = 10000
This approach prevents further complications and reenables the broken functions. In addition, it works for all files and documents.
The requested address that the system cannot assign code exception usually happens when the binding hostname does not have a local network interface. However, we fixed the issue, so let us remember this article’s critical points:
- Your system can encounter a similar error when connecting to the DDB using a non-standard linear policy for all cross-account accesses
- Connecting to the DBD using a non-standard linear policy recreates the warning
- You can fix the assigned requested address that does not function by replacing the short-lived connections to reduce the TCP connections
- The alternative solution suggests modifying the TCP buckets and kernel parameters
You no longer must search for the most sophisticated debugging guide to overcoming the requested address error log. In addition, you will not encounter severe obstacles in implementing the debugging techniques and methods.
Leave a Comment Cancel reply
Save my name, email, and website in this browser for the next time I comment.

IMAGES
VIDEO
COMMENTS
Are you looking to become a Python developer? With its versatility and widespread use in the tech industry, Python has become one of the most popular programming languages today. One factor to consider is whether you prefer self-paced learn...
“Address service requested” for U.S. mail means a piece of mail is forwarded, with no charge, and a separate notice of a new address is provided to the sender for a fee. This occurs for up to a year if a forwarding address is on file with t...
A DHCP host name is an abbreviation for dynamic host configuration protocol, which is a standardized networking protocol used primarily for assigning dynamic IP addresses. Computers use the DHCP to request Internet Protocol parameters, incl...
But if the IP address is 127.0.0.1 it works. Is it related to namespaces? I am executing my server and client codes in another python program by
Docker container [Errno 99] Cannot assign requested address ... Note that for Docker containers, either you need to run them in network_mode: host
ОС Ubuntu Среда anaconda/spyder/ Python 3.8 При запуске выдает ошибку ... Получаю ошибку OSError: [Errno 99] Cannot assign requested address.
Second, by not specifying SOCK_DGRAM in your client, you're getting the default socket type, which is SOCK_STREAM . That means your client is trying to connect
Cannot assign requested address. Данная ошибка говорит вам о том, что нет свободных TCP соеденений. Боротся с ней можно двома способами. — На
OSError: [Errno 99] Cannot assign requested address ... This error is seen when tornado tries to bind IP/port when Jupyter Enterprise Gateway
Hey, I am using dgl==0.4.3 My server is initialized but my client can not connect to the server. Note that they are running in the same
The error message " socket.error : (99, 'Cannot assign requested address ')" is being triggered by a POST request that is being sent multiple
... python --version Python 3.6.3 $ pip freeze certifi==2017.11.5 chardet==3.0.4 cymem==1.31.2 cytoolz==0.8.2 dill==0.2.7.1 en-core-web-sm==2.0
I can use discover_ip_address() without issues, but when using local_ip_address() I get this error: OSError: [Errno 99] Cannot assign
The requested address that the system cannot assign a bug usually happens when the binding hostname does not have a local network interface. However, the