Search code examples
python-3.xsocketsserverserversocketsocketserver

OSError: [Errno 22] Invalid argument?


I promise I will give you 100 reputation if you can solve this in 20 minutes... I'm in very emergent situation.

I'm running this command: python3 ringo.py F 6003 networklab1.cc.gatech.edu 6002 2

poc_address = (poc_name, int(poc_port))
peer_data = json.dumps({
    'command': 'peer_discovery',
    'peers': peers,
    'ttl': 6,
    })
print(poc_address) # ('130.207.107.12', 6002)
server.socket.sendto(
    peer_data.encode('utf-8'),
    poc_address <--- error here..!!
    )

130.207.107.12

I'm getting this error : OSError: [Errno 22] Invalid argument on poc_address

  • Serversocket was defined early

    server = socketserver.UDPServer((HOST, PORT), MyUDPHandler)
    server_thread = Thread(target=server.serve_forever, args=())
    server_thread.daemon = False
    server_thread.start()
    

Solution

  • HOST, PORT = socket.gethostbyname(socket.gethostname()), rather than 127.0.0.1 solved my issue. :)