admin here are my new code: i use new lib: flask-sock
example from flask-sock doc
from flask import Flask
from flask_sock import Sock
app = Flask(__name__)
app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25}
sock = Sock(app)
@sock.route('/echo')
def echo(ws):
while True:
data = ws.receive()
ws.send(data)
passenger_wsgi.py from docs
a very simple html
<!DOCTYPE html>
<html lang="en">
<body>
<div class="container">
<h1>echo:</h1>
<div class="time-display" id="time"></div>
</div>
<script>
let socket = new WebSocket("wss://steviejackson.serv00.net/echo")
console.log(socket.readyState)
</script>
</body>
</html>
the error.log
[2025-08-25 16:09:52,825] ERROR in app: Exception on /echo [GET]
Traceback (most recent call last):
File "/usr/home/steviejackson/.venv/ssn/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/steviejackson/.venv/ssn/lib/python3.11/site-packages/flask/app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/steviejackson/.venv/ssn/lib/python3.11/site-packages/flask/app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/steviejackson/.venv/ssn/lib/python3.11/site-packages/flask/app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/steviejackson/.venv/ssn/lib/python3.11/site-packages/flask_sock/__init__.py", line 59, in websocket_route
ws = Server(request.environ, **current_app.config.get(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/steviejackson/.venv/ssn/lib/python3.11/site-packages/simple_websocket/ws.py", line 290, in __init__
raise RuntimeError('Cannot obtain socket from WSGI environment.')
RuntimeError: Cannot obtain socket from WSGI environment.
Thank you for confirming that WebSockets are supported.but i try again and again,i used flask-sockets before ,i does not work,
now I am using the flask_sock library, and it seems unable to interface with the Passenger environment correctly, leading to the 'Cannot obtain socket' error. Could you please provide a minimal working passenger_wsgi.py and application example for a Python WebSocket setup code? This would help me align my code with your server's specific requirements.
thank again