-
Notifications
You must be signed in to change notification settings - Fork 206
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
Flask app runs in dev, doesn't work in apache mod_wsgi #87
Comments
Hey @fredzannarbor , can you please provide more info on the input request received and if it is correctly being routed to the skill adapter code or is failing even before that? |
OK as follows.
current basketball.py with log statements before and after skill adapter
log output shows that program is reaching points before and after skill adapter
json input from alexa development console
The same script runs fine when I access it via ngrok > flask on local dev. I |
I managed to do some introspection on the skill_adapter object:
Does this look right? I'm getting more puzzled because it sure looks like the basketball flask ask is running. |
Hey @fredzannarbor , the Also, did you remove the |
I removed the app.run/main text from basketball.py
that didn't make any difference. I tried adding a response interceptor before the skill adapter (was that the right place?) but I don't see any output anywhere.
|
Hey @fredzannarbor , I took over the skill code and set it up on Also, by setting the Can you check if the request envelope is reaching route correctly? I am guessing there might be an issue with configuring the flask app through mod_wsgi, which is causing the issue. |
Hey @fredzannarbor , were you able to get this working? |
No, I'm still stuck. I created a separate Flask hello world app (not using ASK at all) that runs via mod_wsgi and performs correctly at https://www.altbrains.com/flasktest. The mod_wsgi log output for each program (basketball.wsgi and flasktest.wsgi) looks the same until the very end when the basketball app's log ends with a 308 PERMANENT REDIRECT instead of 200 for the flasktest log. I don't see why the redirect is being issued. I am wondering about the skill_adapter.register(app=app, route="/") whether it is assuming some sort of default value. I am running apache off a bitnami stack /opt/lampstack... rather than off /var/www/apache. I don't know how to answer your question about the request envelope reaching the route -- how would I double-check that? |
PS I downloaded Postman but I don't know how to manually construct the POST commands to simulate Alexa -- is that available somewhere? I |
Hey @fredzannarbor , sorry to hear that. I am not sure what is leading to HTTP 308 error. Maybe some more debugging and investigating needs to be done.
The
An easy way to check that would be to add a My sample skill wsgi file remains something similar, however I add the virtual env path as required by mod_wsgi, to pick up dependencies. activate_this = '/my_envs/flask_env_virtual/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
sys.path.insert(0, '/sample_project/flask_skill/')
from skill import app as application
Unfortunately, I don't think there is any documentation at the moment. I generally set the following for testing :
This should generally be good enough for testing the request dispatching and output generation. |
I added a request interceptor before all the request handlers. It works via ngrok/Flask alone and correctly reports the request text, but does not find any request when Flask is triggered via mod_wsgi. What is happening seems very similar to this: pallets/flask#2229 a known issue with werkzeug's handling of chunked/multipart requests which flask/werkzeug has (lamely) decided not to fix pallets/flask#2547. However mod_wsgi does appear to be setting wsgi.input_terminated to true, which is the recommended workaround, but that alone doesn't fix the problem for me, so I'm still stuck. At this point I am going to pause and see if I can get gunicorn working with the basketball app. As a side note, the reason I went with mod_wsgi rather than gunicorn was because I expect to have multiple Alexa apps soon, and I didn't want to have to figure out how to have multiple gunicorn endpoints off 443. |
Got things working in production using Apache proxy => gunicorn => flask app, with gunicorn launched by systemd in Ubuntu. Very good article here. https://www.vioan.eu/blog/2016/10/10/deploy-your-flask-python-app-on-ubuntu-with-apache-gunicorn-and-systemd/ |
Thanks for the update @fredzannarbor . Glad you got it working. |
I'm submitting a...
Expected Behavior
App basketball.py is working correctly on Alexa Dev Console > Test > ngrok > endpoint > local dev machine > Flask.
Current Behavior
Now I want to move same app to Apache mod_wsgi since Flask is not production ready. Unfortunately when I then call the app via the wsgi, it does not work and returns null to alexa.
Possible Solution
I suppose I could try to use the generic webservice but then a) I wouldn't be getting the benefits of Flask in dev and b) I don't know how to translate into the request formats for mod_wsgi.
Steps to Reproduce (for bugs)
basketball.wsgi:
The log shows that the endpoint triggers the wsgi (which means the apache conf is correct) and the wsgi tries to run the app, but fails returning null json.
Context
Your Environment
Python version info
The text was updated successfully, but these errors were encountered: