python 发生异常,连接错误:一个或多个命名空间连接失败

3zwjbxry  于 2023-01-24  发布在  Python
关注(0)|答案(2)|浏览(620)

我正在尝试连接到www.example.com服务器并接收消息。但当连接时,我得到socketio。exceptions. ConnectionError:socket.io server and receive messages. But when connecting I get socketio.exceptions.ConnectionError: One or more namespaces failed to connect
代码:

import socketio

sio = socketio.Client()

@sio.event
def connect():
    print('connection established')
    sio.emit('login', {'token': 'token'})

@sio.event
def my_message(data):
    print('message received with ', data)

@sio.event
def disconnect():
    print('disconnected from server')

sio.connect('wss://socket.boticord.top')
sio.wait()

完整错误日志:

Attempting polling connection to https://socket.boticord.top/socket.io/?transport=polling&EIO=4
Polling connection accepted with {'sid': 'JBtkTO-XTOL-OFo2AAAH', 'upgrades': ['websocket'], 'pingInterval': 25000, 'pingTimeout': 5000}
Engine.IO connection established
Sending packet MESSAGE data 0
Attempting WebSocket upgrade to wss://socket.boticord.top/socket.io/?transport=websocket&EIO=4
WebSocket upgrade failed: connection error
Sending polling GET request to https://socket.boticord.top/socket.io/?transport=polling&EIO=4&sid=JBtkTO-XTOL-OFo2AAAH
Unexpected status code 400 in server response, aborting
Waiting for write loop task to end
Sending packet CLOSE data None
Engine.IO connection dropped
Traceback (most recent call last):
  File "c:\Users\Kiril\Documents\senko\bot2\senkobot\main2.py", line 6, in <module>
    sio.connect('wss://socket.boticord.top')
  File "C:\Users\Kiril\AppData\Local\Programs\Python\Python39\lib\site-packages\socketio\client.py", line 338, in connect
    raise exceptions.ConnectionError(
socketio.exceptions.ConnectionError: One or more namespaces failed to connect
HTTP POST request to https://socket.boticord.top/socket.io/?transport=polling&EIO=4&sid=JBtkTO-XTOL-OFo2AAAH failed with error HTTPSConnectionPool(host='socket.boticord.top', port=443): Read timed out. (read timeout=5).
Connection refused by the server, aborting
Exiting write loop task
Exiting read loop task
fsi0uk1n

fsi0uk1n1#

尝试

sio.connect('wss://socket.boticord.top', wait_timeout = 10)
sqxo8psd

sqxo8psd2#

请尝试使用python-socketio的4-5.x版本,或与支持部门联系。

相关问题