user2833462 user2833462 - 2 months ago 36
Python Question

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

My server software says

errno99: cannot assign requested address
while using an ip address other than
for binding.

But if the IP address is
it works.
Is it related to namespaces?

I am executing my server and client codes in another python program by calling
I am actually editing the mininet source code.I edited and inside that I used execfile('') execfile('') and execfile('').So as soon as "sudo mn --topo single,3" is called along with the creation of 3 hosts my server and client codes will get executed.I have given my server and client codes below.

#server code
import select
import socket
import sys
backlog = 5
size = 1024
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
input = [server]
running = 1
while running:
inputready,outputready,exceptready =,[],[])
for s in inputready:
if s == server:
client, address = server.accept()
l = s.recv(1024)

#client code
import socket
import select
import sys
import time
while(1) :
s = socket.socket()
while (1):
f=open ("hello1.txt", "rb")
l =
l =


Stripping things down to basics this is what you would want to test with:

import socket
server = socket.socket() 
server.bind(("", 6677)) 
client_socket, client_address = server.accept()
print(client_address, "has connected")
while 1==1:
    recvieved_data = s.recv(1024)

This works assuming a few things:

  1. Your local IP address (on the server) is (This video shows you how)
  2. No other software is listening on port 6677

Also note the basic concept of IP addresses:

Try the following, open the start menu, in the "search" field type cmd and press enter. Once the black console opens up type ping and this should give you and IP address for google. This address is googles local IP and they bind to that and obviously you can not bind to an IP address owned by google.

With that in mind, you own your own set of IP addresses. First you have the local IP of the server, but then you have the local IP of your house. In the below picture is the local IP of the server which you can bind to. You still own but the problem is that it's owned by the Router and not your server. So even if you visit and that tells you that your IP is that is not the case because it can only see where you're coming from.. and you're accessing your internet from a router.

enter image description here

In order for your friends to access your server (which is bound to you need to forward port 6677 to and this is done in your router. Assuming you are behind one.

If you're in school there's other dilemmas and routers in the way most likely.