0

When I search for this error I found this: socket.gaierror: [Errno 11001] getaddrinfo failed. However, I am not behind a proxy and can't see why this code failed. Note that I have tried both ws and wss and I got the URL from https://www.websocket.org/echo.html and the code example from: WebSocket Programming

test.py:

import clientProtocol as cp
import asyncio
from autobahn.asyncio.websocket import WebSocketClientFactory
if __name__ == '__main__':
    factory = WebSocketClientFactory()
    factory.protocol = cp

    loop = asyncio.get_event_loop()
    coro = loop.create_connection(factory, 'ws://echo.websocket.org')
    loop.run_until_complete(coro)
    loop.run_forever()
    loop.close()

clientProtocol.py:

from autobahn.asyncio.websocket import WebSocketClientProtocol

class clientProtocol:
    def onOpen(self):
        # Add code for authenticate the socket
        print("onOpen")
    
    def onMessage(self):
        # Add code for handling the message
        print(payload)
    
    def onClose(self):
        # Add code for restarting the socket
        print("onClose")

    def onError(self):
        # Add code for logging error and then restart the socket.
        print("onError")

Error:

Traceback (most recent call last):
  File "C:\Users\x\x\test.py", line 21, in <module>
    loop.run_until_complete(coro)
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1017, in create_connection
    infos = await self._ensure_resolved(
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1396, in _ensure_resolved
    return await loop.getaddrinfo(host, port, family=family, type=type,
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 856, in getaddrinfo
    return await self.run_in_executor(
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

Printout as suggested by comment:

host: ws://echo.websocket.org
port: None
family: 0
type: SocketKind.SOCK_STREAM
proto: 0
flags: 0

Worth noting is that I have tried ports 80. 443, 8080

Jesper.Lindberg
  • 313
  • 1
  • 5
  • 14
  • Go into `socket.py` and print out what the inputs are to `getaddrinfo`. I recently had mine fail due to unicode being in my hosts file – Peter Dec 08 '20 at 13:45
  • @Peter updated my post with the information u asked for – Jesper.Lindberg Dec 08 '20 at 15:00
  • 1
    Well, I'm only guessing here, it looks like `getaddrinfo` may not like inputs that aren't an IP address. From what I can gather, it'll just succeed if the IP looks valid, and fail if not. Perhaps your `'ws://echo.websocket.org'` URL is not supported by it. – Peter Dec 08 '20 at 15:51

0 Answers0