与Windows Server的Python Signalr套接字连接

问题描述 投票:0回答:1

我试图建立从python脚本到服务器的套接字连接。我创建了一个基本的连接脚本(在下面),并成功连接到Windows Server 2016(ISS版本:10.0.14393.0)。但是,当我在Windows Server 2019(ISS版本10.0.17763.1)上尝试相同的脚本时,出现此错误:

握手状态400错误的请求类'websocket._exceptions.WebSocketBadStatusException'错误:SignalRCoreClient:握手状态400错误的请求类'websocket._exceptions.WebSocketBadStatusException'

什么可能导致此问题?

Python脚本:

from signalrcore.hub_connection_builder import HubConnectionBuilder

socket_url = 'ws://mysocketurl.com'
def myprint(msg):
    print(msg)
    pass
try:
    print("Starting Connection...")
    hub_connection = HubConnectionBuilder()\
             .with_url(socket_url,
             options={
                   "headers": {
                           "DeviceID": '123123'
                    }
                 })\
                 .with_automatic_reconnect({
                    "type": "raw",
                    "keep_alive_interval": -1,
                    "reconnect_interval": 5
                 }).build()
    hub_connection.on("Connected", myprint)
    hub_connection.start()

except Exception as exc:
    print("Socket stop working. Error:")
    hub_connection.stop()
python sockets signalr windows-server
1个回答
0
投票

从服务器协议列表中,您必须添加WebSocket协议并安装它。在此更新之后,它起作用了。

© www.soinside.com 2019 - 2024. All rights reserved.