Flask Socketio not emitting data to client after running "with app.app_context()" on login process #1794
Replies: 6 comments 7 replies
-
I'm sorry but I don't understand what the problem is. In any case, using a test request context in an application makes absolutely no sense. Not sure what you are trying to achieve, but a test request is only for testing. |
Beta Was this translation helpful? Give feedback.
-
bot.py
router blueprint : auth.py
|
Beta Was this translation helpful? Give feedback.
-
That is my program code... When the user has successfully logged in, the bot will add a scheduler by running task_license_scheduler(). Because there is an interval of 120 seconds, but when the function cron_verify_license runs for the first time (in the app context like in my code), I checked, when I called this code in my function :
or
both will stop socketio to emit data to the client. I don't know how to solve this problem. While the cron_verify_license function I have to run periodically. |
Beta Was this translation helpful? Give feedback.
-
this is my socketio log, first I input "12345", I send, the server emits data "12345" to the client and displays it in html second, I input "123456", I send, the client sends data to the server, but the server does not emit data to the client like the first. between the first and second step, that's when my cron_verify_license function runs. |
Beta Was this translation helpful? Give feedback.
-
SOLVED : Replace flask-socketio with python-socketioHello, @miguelgrinberg, I tried to replace flask-socketio with python-socketio for my application, and everything went smoothly as I expected. So I still believe this might be a bug of flask_socketio, and I'm still very curious about this. haha... These are some steps I did to replace flask_socketio to python-socketio I changed in my file app/_ init _.py :
Becomes
file app/_ init _.py : without socketio.init_app(app)
file bot.py
file events.py the router code on the flask blueprint, as well as the socketio emit is more or less the same. there is only an adjustment for adding the sid argument to the socketio event function like this
|
Beta Was this translation helpful? Give feedback.
-
Yes I know that this is not the best solution at the moment. But I think this is enough, because I will bundle my application into an exe using pyinstaller. So the application will only be run by the user on the computer only. My goal to use socketio is only to update data in real time into my vue js template, so that the client doesn't have to refresh or call ajax periodically to get updated data from the server (backend) But I still wish I could use flask_socketio again. Maybe if you find a solution to what I call this as bug, i will go back to using flask_socketio again. Thank you |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm developing a desktop application using flask.
Where in this application users can login using their email and password.
While using flask-soscketio, I encountered problems logging in.
When the user logs in, the application will authenticate the email and password, if it is successful then my application will call a function to run the scheduler using flask-apscheduler (https://github.com/viniciuschiele/flask-apscheduler) to check the license periodically.
The code is roughly like this:
When the user has successfully logged in, they will be directed to the "homepage", the server should have emitted data to the client.
But when the application calls the task_license_scheduler() function, the server emits any data to the client.
But when I restart the flask application, the socket runs normally and emits data to the client as expected.
This happens only when inside the task_license_scheduler() function involves with app.app_context(), app.test_request_context().
Please give the best solution for this problem. thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions