【问题标题】:python-socketio socketio.exceptions.ConnectionError: One or more namespaces failed to connectpython-socketio socketio.exceptions.ConnectionError:一个或多个命名空间无法连接
【发布时间】:2021-08-06 21:46:17
【问题描述】:

我正在尝试连接到 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

【问题讨论】:

  • 您是否也拥有该服务器,还是第三方?您是否启用了 Socket.IO 日志以查看客户端和服务器之间流量交换的更多详细信息?
  • @Miguel 不,我无权访问服务器。问题肯定在我这边,因为一切都在 node.js 中运行。告诉我如何启用 socket.io 日志?
  • @Miguel 我启用了 socket.io 日志并得到如下输出:Attempting WebSocket upgrade to wss://socket.boticord.top/socket.io/?transport=websocket&amp;EIO=4 WebSocket upgrade failed: connection error Sending polling GET request to https://socket.boticord.top/socket.io/?transport=polling&amp;EIO=4&amp;sid=WDdR53fSdPOcwGVzAAAK Unexpected status code 400 in server response, aborting 基于此,我相信 websocket 出于某种原因尝试更新,但无法更新。
  • 在文档中还写到socket.io的服务器版本是3.0.1,客户端和服务器的版本必须相同。但是在node.js中为客户端指定了版本,我不知道如何为python安装这个版本。

标签: python websocket socket.io python-socketio


【解决方案1】:

试试

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

【讨论】:

    【解决方案2】:

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

    cipherka,后端开发人员

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 2016-05-25
      • 1970-01-01
      相关资源
      最近更新 更多