首页 > 解决方案 > ValueError:方案 https 在 websocket 客户端打招呼中无效

问题描述

我遇到了与这个问题websockets "scheme https is invalid" 类似的问题,但我实际上是在尝试使用 https 问题是我收到了连接指令以从服务器获取数据,并且在该文档中,他给了我列表要连接的服务器。不幸的是,它是https://theirserverurl.com的列表,而不是像往常一样的 wss://。我试图通过以下方式向其中一台服务器打招呼:

from websocket import create_connection
ws = create_connection("https://theirserverurl.com")
print ("Sending 'Hello, World'...")
ws.send("Hello, World")
print ("Sent")
print ("Reeiving...")
result =  ws.recv()
print ("Received '%s'" % result)
ws.close()

我得到的错误是:

ValueError: scheme https is invalid

有什么解决方案可以在 python 上克服这个堆栈。请帮助我。谢谢!

标签: python-3.xwebsocketclientwebsocket

解决方案


您的网址不正确。您应该像这样输入 WSS URL:

wss://live-ws-pg-group3.kuaishou.com/websocket

推荐阅读