telepot icon indicating copy to clipboard operation
telepot copied to clipboard

flask example working with nginx and wsgi

Open molavy opened this issue 8 years ago • 7 comments

i try run flask example with wsgi and nginx so i changed sys.args to manual set variable. telegram never response , i see 200 in nginx response and when i open url in browser i see OK i also add print line before print(request.data) update_queue.put(request.data) # pass update to bot

but i never get telegram response to user

b'{"update_id":651538238,\n"message":{"message_id":103,"from":{"id":259792113,"first_name":"ho","last_name":"ra","username":"rrm"},"chat":{"id":259792113,"first_name":"ho","last_name":"ra","username":"rrm","type":"private"},"date":1482353453,"text":"lj"}}'

molavy avatar Dec 21 '16 20:12 molavy

Hi! I confirm. message_loop() with source queue not working with wsgi.

DanielSerdyukov avatar Jan 18 '17 20:01 DanielSerdyukov

Please confirm, are you guys using uWSGI?

I don't have much experience with wsgi, uwsgi, or nginx. but a web search seems to link nginx with uwsgi (with a 'u' in front). That's why I want to confirm. Thanks.

nickoala avatar Jun 25 '17 04:06 nickoala

Same here, DelegatorBot doesn't seems to work.

naweiss avatar Dec 04 '17 07:12 naweiss

Hi @nickoala, I can confirm this problem for uWSGI. I tried this example, but the request.data that I webhook.feed() does not seem to get forwarded to MessageCounter.

I'm using PythonAnywhere, which features a tutorial for telepot without DelegatorBot. Somebody on their forums tried the same thing and apparently a staff member claimed (currently last post in that thread), that this approach won't work due to telepot's need for an own event-handling loop.

PythonAnywhere uses uWSGI and nginx. The log-files for my webapp on PythonAnywhere start with these lines:

2018-01-28 14:22:21 *** Starting uWSGI 2.0.14 (64bit) on [Sun Jan 28 14:22:18 2018] ***
2018-01-28 14:22:21 compiled with version: 5.4.0 20160609 on 22 November 2017 21:24:09
2018-01-28 14:22:21 os: Linux-4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018

Do you think DelegatorBot can be made working with uWSGI? Any ideas appreciated, happy to help, thanks. :-)

funnyflowerpot avatar Mar 01 '18 23:03 funnyflowerpot

Update: In the log files I have just seen a line saying:

*** Python threads support is disabled. You can enable it with --enable-threads ***

As telepot uses threads, this might be the cause of the problem.

funnyflowerpot avatar Mar 01 '18 23:03 funnyflowerpot

Yes, DelegatorBot in telepot's traditional version uses threads. Any environments that disallow Python threads would not be able to run DelegatorBot.

I personally don't use PythonAnywhere, so can't suggest much here. Either get it to allow threads there, or use telepot's async version, which is based on asyncio (not threads).

nickoala avatar Mar 02 '18 13:03 nickoala

Thanks for the quick reply. Threads are available on PythonAnywhere to non-free accounts only, unfortunately. asyncio raised some hopes, but according to a post from 2015 the used uWSGI implementation doesn't support this either. As the folks at PythonAnywhere suggest to use telepot, I will bring this issue to their attention. Edit: The thread in PythonAnywhere's forums.

funnyflowerpot avatar Mar 02 '18 16:03 funnyflowerpot