-
-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'Response' object has no attribute 'status_code' #223
Comments
How are you starting the server? If you are using gunicorn, please make sure you run with just one worker ( |
Here's my startup command gunicorn --worker-class eventlet -w 1 server:app --bind="127.0.0.1:5000" |
Thanks. I'd seen this before when I was investigating a different gunicorn issue. I actually reported it to the gunicorn guys: benoitc/gunicorn#1147. This error is benign I think, in the sense that it does not prevent the socket communication from happening. It occurs because gunicorn does not recognize the request that is ending is a WebSocket one, and tries to apply the HTTP logic to it. Sounds like I need to write a separate bug for it. |
Oh! I was on gunicorn 18, i see in 19 you have to sepcify the -w 1, I switched to 19.4.5 to see if it keeps happening |
Yeah, this error is in both R18 and R19. |
Ah you're right, I switched and it's still happening. |
@miguelgrinberg did you open up an issue w/ Gunicorn? Was hoping to subscribe to that as well |
I did report it, but as something I discovered while investigating another issue. benoitc/gunicorn#1147 (comment). I believe there is no open issue specific to this problem. |
Submitted one myself, hopefully can get this resolved Thanks, Get to know me on Facebook https://facebook.com/bclark8923 & Twitter On Sun, Feb 14, 2016 at 11:16 PM, Miguel Grinberg [email protected]
|
I noticed the same problem with the same gunicorn config but this error appears only when the client (web navigator or cordova application in my case) is closed suddenly (so the pipe connection is broken). As an example, after the websocket connection my application loops on a request and everything is fine for hours. But as soon as the client is closed abruptly or the page is reloaded, the error appears after 45 to 60 seconds. It looks like an attempt for a reconnection or data exchange from the server to the client and after a timeout. But as the pipe is broken gunicorn is not able to send the request. Does it makes sens ? Can't this come from the Flask-SocketIO module which could try to send something to the client while ignoring the broken hearbeat ? |
Same issue, mark. |
This is a gunicorn issue. Closing. |
I have the same problem. I start only one socket.io worker via command: And I always get error:
What I missing? |
@erm0l0v Does it prevent the server from working? When I saw this (which is a bug in gunicorn, see benoitc/gunicorn#1210), it was benign, in the sense that it happened when a socket connection was ending, and did not stop the server from accepting new connections. |
Yes server works normally. I just get a mount of this kind errors. Should I ignore them? |
@erm0l0v I think there is no other choice at this time than to ignore them. As I said, there is an open issue for this problem with gunicorn, so hopefully it'll be soon fixed. |
Ok. Thank You!! |
@miguelgrinberg There's an update on the issue from gunicorn |
@miguelgrinberg without this fix of gunicorn, do we have any way to handle this error on |
My understanding is that this error is cosmetic, there is no data loss, and the service does not go down because of it. Have you experienced any data loss from this error? |
@miguelgrinberg I got some error like this:
Do you think socketio still works as well in this case without refresh browser? |
The client application has retry logic in it. If any errors occur on the server, the connection will drop and the client will establish a new one right away. A 400 error indicates a potential issue on the server, but without detailed logs I can't really tell you what happened. You should run with logging enabled (add |
Trying out flack as we need a similar websocket python solution that is scalable. |
@w-A-L-L-e You need to read the documentation to learn how to run multiple workers. Gunicorn's |
Thanks for quick reply. That's strange so you can only just use 1 worker -> why even bother with gunicorn ;) Ok so we can do nginx proxy_pass to multiple processes but I thought the whole reason you use something like gunicorn is to keep those workers properly running and kill/restart any that go out of line memory or cpu wise. Anyway it's how unicorn or puma is used in ruby on rails land where you use this to scale the frontend processes (or threads with puma) and afterwards for multiple servers go the nginx proxy_pass route... |
@w-A-L-L-e As I said, this is explained in the documentation... Gunicorn does not support sticky sessions, and that is required for Socket.IO, which is a stateful protocol. The day gunicorn adds sticky sessions (similar to nginx's ip_hash) you will be able to use multiple workers the way you describe. |
Ok, thanks for the info(back from holiday). Anyway the reason I tried gunicorn multiple workers was because when I configured to do the nginx sticky session proxy_pass way I noticed the client (browser inspect) shows long polling instead of true websocket. When it's running in develop mode using python manage.py runserver it does use websocket without long poll. Is this because I'm using python 2.7.x or does that also happen on 3.x or maybe it's due to that error we get: [96865] [ERROR] Error handling request /socket.io/?EIO=3&transport=websocket&sid=57a0b413bca64a1a903bcc953527ecce Basically I see a 101 response (switching protocols) when it tries websocket when this happens then it goes to long polling and gets an ok status. When running in dev mode it does not do the protocol switch. In other words running like this gives me true websockets (but is most likely not optimal for production): |
Anyways above question is not so much important as long as it scales and works with the websocket in long polling mode. A different question I'm extending this project and first thing was to split up the models.py in seperate files in a models dir. The problem is in init.py I need to do book keeping for every file added: #from .models import * # noqa Is there a better way to do that? Next up I tried to add migrations using flask_migrate package (much like in your tutorial here http://blog.miguelgrinberg.com/post/flask-migrate-alembic-database-migration-wrapper-for-flask/page/3). So I tried doing this in the manage.py script: from flask_script import Manager, Command, Server as _Server, Option app = create_app manager.add_command( 'db', MigrateCommand ) But this does not work when you run: you get following errors: |
Ok I solved the migration issue like so. Seems to work ok: working migrations in manage.py :
Then running Now only to solve this import statements in init.py : Any tips on simplifying the from .models. lines into 1 line (like an import * for the whole dir?). |
Not sure I understand the problem. If you want to have all your models in the same module just use a single models.py, or if you want to use a package, just import all the models in the package |
Hi Miquel : I am attempting to start a general non client specific background process that updates song titles on website -- it should broadcast and ideally start before the first webpage is loaded because it monitors song titles and databases them -- but I am using the index page to start the process using the example you wrote here https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/app.py .. I am using 11.1 and have not installed gevent or eventlet.. When I try thread = socketio.start_background_task(target=getSongTitles) I get the error message : "thread = socketio.start_background_task(target=getSongTitles) |
@jackmullen2 what version of Flask-SocketIO do you have? That method was added in version 2.5. |
I just used pip to update .. it went to 11. 1 .. I guess that is 0.11.1 ? i am not sure how to get the latest version .. flask.version |
wow .. sorry .. I was checking flask version .. I upgraded to version 2.2 for flask-socketio .. the results produced this message " |
i can't fix it. please help. |
I'm using Flask-SocketIO (2.4) and it seems pretty stable without issues for me...
This works fine and has right app context... |
@w-A-L-L-e hi! could talk about more about your code? |
Thought it would help basically I had same context/thread issue in beginning so I posted it here. By using the before first request the part with app.app_context() seemed to work correctly. We also kept track of the sockets in database (postgres) that allowed to do cleanup/offline detection a bit better for our use case... Only thing to mention is we have jenkins build server always call a /stats route with curl after deploy so we know this cleanup thread is always running... Ow and that import stuff from way back is not really an issue anymore (or rather I don't need to change the imports much so I can live with it...) Anyway hope it helped. Keep up the good work. |
@miguelgrinberg : Still getting the same error with gunicorn and two worker threads. Would you suggest using uWSGI or any other wsgi supported servers other than gunicorn? |
You can't use multiple workers with Gunicorn when you have the Flask-SocketIO extension. Try one worker. |
@miguelgrinberg : Thank you! that worked |
I solved my problem by install flask-sockets and flask-sock :
|
I continually get the error listed below. Nothing seems to break but I'd like to clean it up. Any ideas what causes this?
The text was updated successfully, but these errors were encountered: