Reputation: 31
I'm trying to make a turn-based game in Godot that is hosted on an external server to prevent cheating. Websockets seem to be the best solution and Heroku apparently supports websockets. I'm trying to use flask-sockets to accomplish this but cannot get anything to work. I keep getting this error in my Heroku logs:
2022-08-10T01:13:42.934964+00:00 app[web.1]: Traceback (most recent call last):
2022-08-10T01:13:42.934997+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gevent/pywsgi.py", line 999, in handle_one_response
2022-08-10T01:13:42.934998+00:00 app[web.1]: self.run_application()
2022-08-10T01:13:42.935002+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/geventwebsocket/handler.py", line 75, in run_application
2022-08-10T01:13:42.935002+00:00 app[web.1]: self.run_websocket()
2022-08-10T01:13:42.935004+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/geventwebsocket/handler.py", line 52, in run_websocket
2022-08-10T01:13:42.935005+00:00 app[web.1]: list(self.application(self.environ, lambda s, h, e=None: []))
2022-08-10T01:13:42.935017+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2548, in __call__
2022-08-10T01:13:42.935018+00:00 app[web.1]: return self.wsgi_app(environ, start_response)
2022-08-10T01:13:42.935029+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_sockets.py", line 40, in __call__
2022-08-10T01:13:42.935029+00:00 app[web.1]: handler, values = adapter.match()
2022-08-10T01:13:42.935039+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/werkzeug/routing/map.py", line 622, in match
2022-08-10T01:13:42.935040+00:00 app[web.1]: raise WebsocketMismatch() from None
2022-08-10T01:13:42.935067+00:00 app[web.1]: werkzeug.routing.exceptions.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
2022-08-10T01:13:42.935181+00:00 app[web.1]: 2022-08-10T01:13:42Z {'REMOTE_ADDR': '10.1.31.248', 'REMOTE_PORT': '12800', 'HTTP_HOST': 'reversertesterheroku.herokuapp.com', (hidden keys: 33)} failed with WebsocketMismatch
Here is my Flask app:
from flask import Flask
from flask_sockets import Sockets
app = Flask(__name__)
sockets = Sockets(app)
@sockets.route('/reverse')
def echo_socket(ws):
while not ws.closed:
message = ws.receive()
ws.send(message[::-1])
@app.route('/')
def hello():
return "Hello World!"
Every websocket testing method I use does not work so I am almost 100% certain something is wrong on the server side.
This is all of my Heroku files if everything above isn't enough. PLEASE help me find a solution or a working alternative.
Upvotes: 3
Views: 301