socketio使用回调提示create_client..test()缺少1个必需的位置参数:'ack'

发布于 2025-01-10 09:05:34 字数 390 浏览 5 评论 0原文

服务器代码:

  def test_call_back(text):
         print(text)
  sio.emit('test', 'test call back', callback=test_call_back)

客户端代码:

@sio.on('test')
def test(data,ack):
    print(data)
    ack()

运行错误提示:

create_client.<locals>.test() missing 1 required positional argument: 'ack'

我应该如何使用回调?

server code:

  def test_call_back(text):
         print(text)
  sio.emit('test', 'test call back', callback=test_call_back)

cliend code:

@sio.on('test')
def test(data,ack):
    print(data)
    ack()

run wrong tips:

create_client.<locals>.test() missing 1 required positional argument: 'ack'

How should I use callback?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⊕婉儿 2025-01-17 09:05:34

您似乎正在使用 JavaScript 客户端文档并将其应用到 Python 客户端。 Python 客户端不是克隆版本,因此请使用 Python 文档。对于回调: https://python-socketio.readthedocs.io /en/latest/client.html#event-callbacks

向另一端返回两个值的示例 ack:

@sio.event
def my_event(sid, data):
    # handle the message
    return "OK", 123

You seem to be using the JavaScript client documentation and applying that to the Python client. The Python client is not a clone, so please use the Python documentation instead. For callbacks: https://python-socketio.readthedocs.io/en/latest/client.html#event-callbacks.

Example ack that returns two values to the other side:

@sio.event
def my_event(sid, data):
    # handle the message
    return "OK", 123
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文