我正在尝试复制 websocket 连接。在带有 JavaScript 的 HTML 代码中,连接完美地发生。但是,在 python 中使用与 websockets 或 websocket-client 相同的标头,我收到以下错误:
Handshake status 401 Unauthorized
{'content-type': 'application/json; charset=utf-8', 'content-length': '0', 'connection': 'close', 'date': 'Sun, 16 Jun 2024 22:56:20 GMT', 'x-cache': ' Error from cloudfront'}
为什么会发生这种情况?我要停止发送什么?
尝试使用
websocket.enableTrace(True)
检查您的请求标头是否存在重复。
链接到文档https://websocket-client.readthedocs.io/en/latest/examples.html#debug-and-logging-options
我们在 websocket-client 上也遇到了同样的问题。当标头无效时,CloudFront 返回 401。