小编ggj*_*ono的帖子

Python socketio badnamespaceerror 在一台设备上出现异常,但在另一台设备上不起作用

大家好,我有以下代码,但由于某种原因,我不断收到以下错误,但它似乎可以在同事的电脑上运行。我们似乎无法弄清楚为什么这对我的不起作用。

我们还仔细检查了我们是否使用 dir() 导入相同的 socketio

我尝试在 sio.connect 和 sio.emit 中指定名称空间,但仍然没有成功!

socketio.exceptions.BadNamespaceError: / is not a connected namespace.

bearerToken = 'REDACT'

core = 'REDACT'
output = 'REDACT'


import socketio
import json

def getListeners(token, coreUrl, outputId):
    sio = socketio.Client(reconnection_attempts=5, request_timeout=5)
    sio.connect(url=coreUrl, transports='websocket')

    @sio.on('mwedge:batch:stats')
    def batchStats(data):
        if (outputId in data['outputStats']):
            listeners = data['outputStats'][outputId][16]
            print("Number of listeners ", len(listeners))
            ips = []
            for listener in listeners:
                ips.append(listener[1])
            print("Ips", ips)

    def authCallback(data):
        print(json.dumps(data))

    sio.emit(event='auth',
    data={
        'token': token
    },
    callback=authCallback)


getListeners(bearerToken, core, output)
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-socketio

2
推荐指数
1
解决办法
3796
查看次数

标签 统计

python ×1

python-3.x ×1

python-socketio ×1