python - python-socketio socketio.exceptions.ConnectionError:一个或多个命名空间无法连接
问题描述
我正在尝试连接到 socket.io 服务器并接收消息。但是在连接时我得到 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
解决方案
尝试
sio.connect('wss://socket.boticord.top', wait_timeout = 10)
推荐阅读
- tkinter - Tkinter 背景换色器
- sql - 在子查询中使用 where 选择查询
- sql - 加入三个不同的表后删除重复项
- node.js - Nodemailer 使用特定的出站端口
- node.js - 在管理员兄弟中使用现有的 api 和控制器登录
- authentication - 身份验证返回 400 和“出现问题”,但在隐身模式下工作
- php - yii2 - SQLSTATE [23000]:完整性约束违规:1048
- javascript - 如何在javascript图中制作标签范围
- python-3.x - Google colab 一直在下载 Fashion_Mnist 数据集
- c# - EF Core 3.1 到 5 更新 -> IEntityType.GetTableName