When use Flask and Flask-SocketIo says an error:
app = Flask(...)
socketio = SocketIO(app)
# .. routes and blueprints without socket routes
socketio.run(app=app, host='127.0.0.1', port=9999)
Traceback (most recent call last):
File "/home/.../.local/lib/python3.8/site-packages/gevent/pywsgi.py", line 999, in handle_one_response
self.run_application()
File "/home/.../.local/lib/python3.8/site-packages/geventwebsocket/handler.py", line 82, in run_application
self.process_result()
File "/home/.../.local/lib/python3.8/site-packages/gevent/pywsgi.py", line 932, in process_result
self.write(data)
File "/home/.../.local/lib/python3.8/site-packages/gevent/pywsgi.py", line 779, in write
self._write_with_headers(data)
File "/home/.../.local/lib/python3.8/site-packages/gevent/pywsgi.py", line 800, in _write_with_headers
self._write(data)
File "/home/.../.local/lib/python3.8/site-packages/gevent/pywsgi.py", line 762, in _write
self._sendall(data)
File "/home/.../.local/lib/python3.8/site-packages/gevent/pywsgi.py", line 736, in _sendall
self.socket.sendall(data)
File "/home/.../.local/lib/python3.8/site-packages/gevent/_socketcommon.py", line 698, in sendall
data_memory = _get_memory(data)
File "src/gevent/_greenlet_primitives.py", line 98, in gevent._gevent_c_greenlet_primitives.get_memory
File "src/gevent/_greenlet_primitives.py", line 121, in gevent._gevent_c_greenlet_primitives.get_memory
File "src/gevent/_greenlet_primitives.py", line 109, in gevent._gevent_c_greenlet_primitives.get_memory
TypeError: memoryview: a bytes-like object is required, not 'str'
2021-03-08T01:38:48Z {'REMOTE_ADDR': '127.0.0.1', 'REMOTE_PORT': '32906', 'HTTP_HOST': '127.0.0.1', (hidden keys: 21)} failed with TypeError
I test using netcat:
$ ncat --crlf -v 127.0.0.1 9999
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:9999.
GET / HTTP/1.1
Host: 127.0.0.1
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: 0
Origin: http://127.0.0.1
HTTP/1.1 426 Upgrade Required
Sec-WebSocket-Version: 13, 8, 7
Date: Mon, 08 Mar 2021 01:38:48 GMT
Content-Length: 37
Or with curl same issue:
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: 127.0.0.1" -H "Origin:http://127.0.0.1:9999" http://127.0.0.1:9999/
HTTP/1.1 426 Upgrade Required
Sec-WebSocket-Version: 13, 8, 7
Date: Mon, 08 Mar 2021 01:35:39 GMT
Content-Length: 37
curl: (18) transfer closed with 37 bytes remaining to read
But with echo.websocket.org works fine:
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: http://www.websocket.org" http://echo.websocket.org
HTTP/1.1 101 Web Socket Protocol Handshake
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Headers: authorization
Access-Control-Allow-Headers: x-websocket-extensions
Access-Control-Allow-Headers: x-websocket-version
Access-Control-Allow-Headers: x-websocket-protocol
Access-Control-Allow-Origin: http://www.websocket.org
Connection: Upgrade
Date: Mon, 08 Mar 2021 01:46:41 GMT
Server: Kaazing Gateway
Upgrade: WebSocket
WebSocket-Location: ws://echo.websocket.org/
WebSocket-Origin: http://www.websocket.org
In the code using a simple Flask app and SocketIO wrapper. In StackOverflow says the problem is a incompatibility with python3: https://stackoverflow.com/questions/38269696/python-flask-socketio-typeerror-a-bytes-like-object-is-required-not-str :
I think you use python3 with the gevent and gevent-websocket plugin. gevent-websocket does not support python3 yet.
But in the pip package says the module is for python3.
When use Flask and Flask-SocketIo says an error:
I test using netcat:
Or with curl same issue:
But with echo.websocket.org works fine:
In the code using a simple Flask app and SocketIO wrapper. In StackOverflow says the problem is a incompatibility with python3: https://stackoverflow.com/questions/38269696/python-flask-socketio-typeerror-a-bytes-like-object-is-required-not-str :
But in the pip package says the module is for python3.