连接到Heroku上的服务器:websocket._exceptions.WebSocketBadStatusException:握手状态404未找到

时间:2019-05-11 15:41:39

标签: python heroku flask websocket

我正在尝试在heroku上的服务器和计算机上的客户端之间建立连接,但是当我尝试建立连接时得到以下提示。

我看了heroku提供的教程,但是没有用。当我运行客户端代码时,它会出现以下异常:

Traceback (most recent call last):
File "client.py", line 4, in <module>
      ws = create_connection("wss://securitysys.herokuapp.com/relay")
File"/home/yukinari/.local/lib/python3.5/sitepackages/websocket/_core.py", line 514, in create_connection
      websock.connect(url, **options)
File "/home/yukinari/.local/lib/python3.5/site-packages/websocket/_core.py", line 226, in connect
      self.handshake_response = handshake(self.sock, *addrs, **options)
File "/home/yukinari/.local/lib/python3.5/site-packages/websocket/_handshake.py", line 79, in handshake
     status, resp = _get_resp_headers(sock)
File "/home/yukinari/.local/lib/python3.5/site-packages/websocket/_handshake.py", line 160, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
    websocket._exceptions.WebSocketBadStatusException: Handshake status 404 NOT FOUND

我的代码:

app.py

@sockets.route('/relay')
def relay_msg(ws):
    while not ws.closed:
        message = ws.receive()
        print(message)
        ws.send(message)

client.py

ws = create_connection("wss://MyAppName.herokuapp.com/relay")
ws.send("hello world!")
ws.recv()

0 个答案:

没有答案