Python 到 Windows 服务器的信号器套接字连接
Python signalr socket connection to Windows Server
我试图建立从我的 python 脚本到我的服务器的套接字连接。我创建了一个基本连接脚本(如下所示)并成功连接到 Windows Server 2016 (ISS version: 10.0.14393.0)。但是当我在 Windows Server 2019(ISS 版本 10.0.17763.1)上尝试相同的脚本时,我收到了这个错误:
Handshake status 400 Bad Request class 'websocket._exceptions.WebSocketBadStatusException'
ERROR:SignalRCoreClient:Handshake status 400 Bad Request class '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()
从服务器协议列表中,您必须添加 WebSocket 协议并安装它。这次更新后它工作了。
我试图建立从我的 python 脚本到我的服务器的套接字连接。我创建了一个基本连接脚本(如下所示)并成功连接到 Windows Server 2016 (ISS version: 10.0.14393.0)。但是当我在 Windows Server 2019(ISS 版本 10.0.17763.1)上尝试相同的脚本时,我收到了这个错误:
Handshake status 400 Bad Request class 'websocket._exceptions.WebSocketBadStatusException' ERROR:SignalRCoreClient:Handshake status 400 Bad Request class '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()
从服务器协议列表中,您必须添加 WebSocket 协议并安装它。这次更新后它工作了。