I am trying to deploy the first zappa example app built with Flask-Ask, It looks like everything works good but after the Deploying API statement I get the following error :
Error: Warning! Status check on the deployed lambda failed. A GET request to '/'
yielded a 502 response code.
Here is the code I am executing with minor changes to the sample app
from flask import Flask
from flask_ask import Ask, question, statement, session
import pyodbc
app = Flask(name)
ask = Ask(app, '/')
#ask.intent('HelloIntent')
def hello(firstname):
speech_text = "Hello %s" % firstname
return statement(speech_text).simple_card('Hello', speech_text)
#ask.intent('ByeIntent')
def bye():
return statement("Ok, goodBye!")
if name == 'main':
app.run()
Zappa version used: 0.46.1
Operating System and Python version: Windows 7, Python 3.6
Can someone please help me out here?
try installing all the dependencies using pip in the virtual environment where you are using zappa. It worked in my case.
You can also use zappa tail command to see your logs.
This github issue seems to have the same symptoms.
Downgrading to zappa==0.45.1 solved it for me
If you are using anaconda than create a new virtual environment "virtualenv lambda" in your project directory and in Scripts/activate. Than deactivate the conda environment with "conda deactivate" and pip install all the packages "pip install numpy pandas sklearn zappa flask".
PS: using "slim_handle"=true also gives this error, so don't use it.
If all of above doesn't work you can solve it by this way.
First solve all errors by checking the app log by zappa tail [app name], if you have any
Then,
You must provide "app_function" parameter in the zappa_settings.json which should point to your entry function. The app_function should be provided like this if application is Flask __init__.application, so the flask app should be defined as application as follows,
application = Flask(__name__)
app.py should be __init__.py
You have to add __init__.py in order to recognize your project folder as a package.
So zappa_settings.json have parameter like this,
"app_function": "__init__.application",
Deploy and enjoy!
I was facing this error when I gave the modular path to my application as main.py.
I fixed it by creating an empty file called main.app just next to main.py and setting app_function to main.app in zappa_settings.json.
Absolutely no clue what happened underneath, but it worked for me.
I had same problem. After spending couple of hours, from cloudwatch logs I noticed the error of sec certificate. Solved it by running "pip install 'cryptography<2.2'"
I faced the same error, and same what happened with ScottieB above, the reason was that I forgot to do the pip install for one package that my .app was using...After I did the pip install locally in the project environment then did the zappa update dev the error gone! and update been completed.
I had this same error and after many online searches and trying many, many suggestions, it was actually just a small problem with a code indentation! No problem with Zappa config or pip installations at all.
I notice that in your code sample you have not indented your code at all. I don't know if this is how it copy pasted into StackOverflow or if this is how you unintentionally tried to deploy it. It should be
#ask.intent('HelloIntent')
def hello(firstname):
speech_text = "Hello %s" % firstname
return statement(speech_text).simple_card('Hello', speech_text)
#ask.intent('ByeIntent')
def bye():
return statement("Ok, goodBye!")
if name == 'main':
app.run()
I was getting same error.
check you have installed zappa in your venv.
I have installed globally and run in local venv. When i installed zappa it works perfect.
I was facing the same issue and I figured out that zappa is installed globally on my system not in the virtual env that I am using.
try installing zappa in virtual env
pip install zappa
I was running a flask app and forgot to include following statement in my app.
if __name__ == '__main__': app.run()
after adding this line it started working fine.
👍
Related
I am trying to create project using python, flask and pycharm. While I was deploying the code using "flask deploy" command, I got "OSError: Could not locate nacl lib, searched for libsodium" issue. I could not solve the issue since I am new to python, flask and pycharm.
Need help.
I solved this issue by running
sudo apt-get install python3-nacl
I'm following this link Deploy to Production
After having deployed the whl file on the server, then installed it through pip, if I run pip list the package is present. But in a python console I can't import it.
Is there any reason ?
Following this tutorial packaging-projects, is it mandatory to upload the package as explained in the "Uploading the distribution archives" section ?
Thanks
I followed the link in my 1st post to create a package and I discovered the tree files was not correct. So I rearranged it and now it's fine
folks. I recently wrote my first python Flask app, a simple data wrangling app that has the Pandas library as the only extra dependency (apart from Flask itself).
It retrieves data from online csv files, process them and return a few numbers inside a text. (I use no database. It takes the data from these online files and returns the result to the browser screen without storing it.)
I've built it within a conda environment for which I added only Pandas and Flask libraries. And it ran perfectly on my localhost.
But now I'm having a hard time trying to deploy it to Heroku...
First I generated my Procfile and a requirements.txt file using pip:
pip freeze > requirements.txt
But then, when I try to deploy the app, Heroku returns a series of errors related do "mkl" dependencies. I'm not sure if these are related to pandas, but here what they are: mkl-service==2.3.0, mkl_fft==1.3.0 and mkl_random==1.1.1.
I tried to change the versions of the packs, choosing versions suggeted by Heroku, but it didn't work for mkl-service, which seems to be not supported at all by Heroku. I then just erased this line and took a chance. I managed to deploy the app with no error messages, but then the app doesn't run.
I also tried to generate my requirements.txr file through conda rather than pip.
conda list -e requirements.txt
It generates a weird file with "=" operators rather than "==", which I corrected through search/replace and deleting info on endcaps. This time, it also included mkl==2020.2, a dependency that has over 300 MB and didn't make my app work properly neither.
I wonder if the problem with my app has to do with some mess I did by mixing conda and pip for my environment. Or maybe it has to do with getting pandas to work online. I wonder if some of you might know what's going wrong.
After trying several combinations I managed to get the app to work by creating a requirements.txt that takes only the names of gunicorn and the packages I had originally installed in my local enviroment
Flask
pandas
gunicorn
Of course, Flask and pandas have their own dependencies, but it turns out Heroku automatically installs them, just like pip does. So, this time, making requirements.txt as simple as possible worked fine.
I'm more or less new to computer science and can not even manage to run my first "Hello World" in Flask (Python 3; on my Windows-10 computer). I have tried some different tutorials on how to get started with Flask but did not find them really helpful so I did not finish them. Eventually I found a tutorial that seemed comprehensive and fitting my needs, but Visual Studio Code Terminal could not execute my code but gave me back an Error Message. Maybe I created a global virtual environment before I started this course that I'm following along now, and that's why it gives me that Error, but am not sure.
So this is the tutorial that I eventually picked and am currently following along: https://www.youtube.com/watch?v=QjtW-wnXlUY.
The tutorial showed me how to set up and activate a local virtual environment in my project folder and pip install Flask as well as save app.py, with the help of my command batch and VSCode.
Then the user should try and run the following code (see below this paragraph). On my browser it really worked perfectly fine, but the Visual Studio Code-Terminal gave me an error message called "ModuleNotFoundError: No module named 'flask'" (I know there are some similar-named threads out there in stackoverflow, but the answers given did not help me with my problem and also it seems to me that my case is slightly different). So this is the code I tried to run in Visual Studio Code:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def index():
return "Hello world!"
And this is the complete ErrorMessage that Visual Studio Code-Terminal gave me:
PS C:\Program Files\DB Browser for SQLite> & C:/Users/User/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/User/Desktop/Flask_app/app.py
Traceback (most recent call last):
File "c:/Users/User/Desktop/Flask_app/app.py", line 1, in <module>
from flask import Flask
**ModuleNotFoundError: No module named 'flask'**
PS C:\Program Files\DB Browser for SQLite>
Any ideas what's wrong with my code? Maybe it has to do with the path I stored it in? I got no idea; am very thankful for help!
Cheers.
Make sure the virtual environment you created is activated before running the app.
Also make sure it is activated when you run 'pip install flask'.
first install the flask in your system
pip install flask
run the flask server then try it
> set FLASK_APP=hello
> flask run
I'm learning a little bit how function python, more specific Flask.
I'm creating a new project using flask, but when I create a new file and import Flask I receive this error: No name 'Flask' in module 'flask'pylint(no-name-in-module)
I did read that, I need create a file called: __init__.py but I have this and the error keeps showing up.
This is my actual code (very simple code, and folder/files structure):
Thanks for the help! :D
I tried this: Flask ImportError: No Module Named Flask, but this solution does not works for me.
I installed flask on python 2.7 and run simple hello world script and it worked fine. Then I updated python to python 3.8 and I got an error similar to yours:
Unable to import 'flask'pylint(import-error)
I simply uninstalled flask and installed again and it worked for me. Run this two commands:
pip uninstall flask
pip install flask
Then export the FLASK_APP environment variable and run flask
set FLASK_APP=file.py
flask run
I solved this changing my python interpreter. I did uninstall pylint and install pylama and now all is fine!