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