Any kind of connection is tried to be upgraded to WS connection #43
Comments
Hi @winster, Sorry, I cannot confirm this currently. I've tried to run this: from flask import Flask, Blueprint
from flask_sockets import Sockets
router = Blueprint('router', __name__)
ws = Blueprint('ws', __name__)
@ws.route('/socket')
def web_socket(socket):
app.logger.debug("inside 'web_socket'")
while not socket.closed:
message = socket.receive()
socket.send(message)
@router.route('/status', methods=['POST'])
def status():
app.logger.debug("inside 'status'")
return("hello from status\n")
app = Flask(__name__)
app.config['DEBUG'] = True
app.register_blueprint(router)
sockets = Sockets(app)
sockets.register_blueprint(ws) using Gunicorn: gunicorn -k flask_sockets.worker --reload flask_sockets_bug_43:app and tried to curl -X POST http://127.0.0.1:8000/status So, I've got in response
and here are log messages:
P.S.: Thanks |
Can you try first connecting to websocket and then hit the status API? |
Hi, yes Here we go to WS: curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: localhost:8000" -H "Origin: http://localhost" -H "Sec-Websocket-Version: 13" -H "Sec-Websocket-Key: y0eGBK40KPi4DQhEo7l02Q==" http://localhost:8000/socket Output:
And plain HTTP:
Output:
Logs:
What is your OS, version of Python and libraries? How are you connecting to WS? Where do those messages
come from? |
I am using Heroku cloud server. Probably it is a Linux distribution, 2.7 'Initializing WebSocket' is not my log. Is it from gevent? Below another example.
|
Well, Due to code, it is expected to see However, your log contains a part of traceback interweaved between those messages. This is very suspicious:
I also have a service deployed to Heroku which has both HTTP endpoints and WS endpoints. I make POST requests before and after connecting to WS and there is nothing similar to your messages:
Have you tried to make bare requests to your services from console or special tools? It's hard to give a vivid answer without seeing implementation of both server and client. Thanks |
I understand. Let me dig more. The same client worked with NodeJS websocket. |
I confirm this issue. I do not know, why nothing is put into logs, but yes, |
And here's log for POST request:
|
So, This is a valid logic, since a web server listens for all incoming connections on a single socket. Hence, all connections are passed through same logic: handler checks whether connection is a websocket connection or not. And there are vivid messages for that: if self.environ.get('REQUEST_METHOD', '') != 'GET':
# This is not a websocket request, so we must not handle it
self.logger.debug('Can only upgrade connection if using GET method.')
return
if upgrade == 'websocket':
...
else:
# This is not a websocket request, so we must not handle it
return So, your messages
are not errors, they are just debug messages. Nothing goes wrong. I agree that they are confusing and the only thing you can do is to open an issue in gevent-websocket and to ask to write more correct messages to logs. Other thing you can do is set up a logging handler for a logger named Does this answer your question? |
@winster can this issue be closed? |
closing this |
Hello,
I am using both flask router and flash-sockets. That means, my server has both http and websocket end points. After flash-socket integration, any calls to my http router also try to upgrade the request. And getting following error.
This is how I register blueprint in init.py
And in router.py
What went wrong?
The text was updated successfully, but these errors were encountered: