SignalR 与 Python websocteks 返回 503

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

我在 ASP.NET Core 中创建了最简单的 Hub,并将其推送到包含以下代码的 Azure:

public class TestHub: Hub
{
}

app.UseEndpoints(endpoints =>
{
   endpoints.MapControllers();
   endpoints.MapHub<TestHub>("/testHub");
});

为了验证集线器是否正常工作并且客户端有可能检索消息我使用 Microsoft.SignalR 客户端库创建了控制台应用程序:

var url = "{baseUrl}/testHub";

var connection = new HubConnectionBuilder()
      .WithUrl(url)
      .WithAutomaticReconnect()
      .Build();

connection.On("OpenDoors", () =>
{
   Console.Write("Message");
});

await connection.StartAsync();

通过上述解决方案,我能够从部署到 Azure 的 SignalR 中检索消息。

现在我正在尝试使用 Python 和它的 websockets 做同样的事情。

为了实现这一点,我进行谈判:

negotiation = requests.post('https://{url}/testHub/negotiate?negotiateVersion=0', verify=False).json()

返回正确的值。我现在正在尝试握手:

connectionId = negotiation['connectionId'])

async with websockets.connect('wss://{url}/testHub?id={connectionId }') 

在那里我检索和错误:

websockets.exceptions.InvalidStatusCode:服务器拒绝 WebSocket 连接:HTTP 503

我想念什么?

python websocket signalr
© www.soinside.com 2019 - 2024. All rights reserved.