user8513564
user8513564

Reputation:

Python - socket.error: Cannot assign requested address

I have written a chat server but I cannot bind my socket to an IP address:

import sys
import os
import socket

HOST = "194.118.168.131"
SOCKET_LIST = []
RECV_BUFFER = 4096 
PORT = 9009

def chat_server():

    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind((HOST, PORT))
    server_socket.listen(10)
...

I get the following error:

Traceback (most recent call last):
  File "server.py", line 83, in <module>
    sys.exit(chat_server())
  File "server.py", line 20, in chat_server
    server_socket.bind((HOST, PORT))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address

What's wrong with my code?


I didn't find an answer on:

'Connection aborted.', error(99, 'Cannot assign requested address') error in Python,
socket.error[Errno 99] Cannot assign requested address,
bind: cannot assign requested address
Cannot assign requested address - possible causes?

Upvotes: 6

Views: 39401

Answers (1)

llllllllll
llllllllll

Reputation: 16404

By checking errno.h, errno 99 is EADDRNOTAVAIL. The man page bind(2) says:

EADDRNOTAVAIL A nonexistent interface was requested or the requested address was not local.

It is often caused by a wrong IP address. You can use the command ifconfig to check whether your machine has this IP address.

Upvotes: 9

Related Questions