0
votes

I have deployed Python-Flask API in Azure. Its working fine in development environment. It has following dependencies which is mentioned in a .txt file.

  • click==6.7
  • Flask==1.0.2
  • itsdangerous==0.24
  • Jinja2==2.10
  • MarkupSafe==1.0
  • Werkzeug==0.14.1
  • jsonpickle==1.0
  • pyodbc==4.0.25

I have an app.py class which has some function that contains some DB CURD operations. It also has a db.py which contain below code :

import pyodbc cnxn = pyodbc.connect(cs)

But when I am navigating to https://kmsazapi.azurewebsites.net/ it is giving below error
:( Application Error. If you are the application administrator, you can access the diagnostic resources.

Please find the Application logs from Azure :

2019-01-19T16:30:46.743756546Z 2019-01-19T16:30:46.893500456Z Starting OpenBSD Secure Shell server: sshd. 2019-01-19T16:30:46.921319668Z Running python /usr/local/bin/entrypoint.py 2019-01-19T16:30:47.042444539Z executing: 2019-01-19T16:30:47.042628845Z python --version 2019-01-19T16:30:47.060630336Z Python 3.7.1 2019-01-19T16:30:47.060830442Z executing: 2019-01-19T16:30:47.060993448Z pip --version 2019-01-19T16:30:49.209547693Z pip 10.0.1 from /home/site/wwwroot/antenv/lib/python3.7/site-packages/pip (python 3.7) 2019-01-19T16:30:49.214266747Z found flask app 2019-01-19T16:30:49.219978635Z executing: 2019-01-19T16:30:49.219990835Z . antenv/bin/activate 2019-01-19T16:30:49.224706090Z 2019-01-19T16:30:49.224798193Z executing: 2019-01-19T16:30:49.224971698Z GUNICORN_CMD_ARGS="--bind=0.0.0.0 --timeout 600" gunicorn application:app 2019-01-19T16:30:50.183264018Z [2019-01-19 16:30:50 +0000] [36] [INFO] Starting gunicorn 19.9.0 2019-01-19T16:30:50.183984042Z [2019-01-19 16:30:50 +0000] [36] [INFO] Listening at: http://0.0.0.0:8000 (36) 2019-01-19T16:30:50.184216749Z [2019-01-19 16:30:50 +0000] [36] [INFO] Using worker: sync 2019-01-19T16:30:50.194083973Z [2019-01-19 16:30:50 +0000] [39] [INFO] Booting worker with pid: 39

2019-01-19T16:30:50.967282324Z [2019-01-19 16:30:50 +0000] [39] [ERROR] Exception in worker process

2019-01-19T16:30:50.967302024Z Traceback (most recent call last): 2019-01-19T16:30:50.967306124Z File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker 2019-01-19T16:30:50.967311525Z worker.init_process() 2019-01-19T16:30:50.967325625Z File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process 2019-01-19T16:30:50.967329625Z self.load_wsgi() 2019-01-19T16:30:50.967332825Z File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi 2019-01-19T16:30:50.967336425Z self.wsgi = self.app.wsgi() 2019-01-19T16:30:50.967347026Z File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi 2019-01-19T16:30:50.967350926Z self.callable = self.load() 2019-01-19T16:30:50.967354226Z File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load 2019-01-19T16:30:50.967357626Z return self.load_wsgiapp() 2019-01-19T16:30:50.967361026Z File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp 2019-01-19T16:30:50.967364426Z return util.import_app(self.app_uri) 2019-01-19T16:30:50.967367726Z File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app 2019-01-19T16:30:50.967371427Z import(module) 2019-01-19T16:30:50.967374727Z File "/home/site/wwwroot/application.py", line 7, in 2019-01-19T16:30:50.967378427Z import db 2019-01-19T16:30:50.967381627Z File "/home/site/wwwroot/db.py", line 1, in 2019-01-19T16:30:50.967385027Z import pyodbc 2019-01-19T16:30:50.967388327Z ImportError: libodbc.so.2: cannot open shared object file: No such file or directory 2019-01-19T16:30:50.967653236Z [2019-01-19 16:30:50 +0000] [39] [INFO] Worker exiting (pid: 39) 2019-01-19T16:30:51.050986468Z [2019-01-19 16:30:51 +0000] [36] [INFO] Shutting down: Master 2019-01-19T16:30:51.051229076Z [2019-01-19 16:30:51 +0000] [36] [INFO] Reason: Worker failed to boot. 2019-01-19T16:30:51.102156846Z

What I am missing ?

1

1 Answers

1
votes

Update: 0115:

If you deploy the python app to web app for windows, you can install the python extension as below: Go to azure portal -> your app service -> Extensions -> Add -> choose extensions:

enter image description here

enter image description here


How do you deploy your flask app?

You can refer to the official doc for the deployment. I followed the doc, and can work well in azure with the site https://xxx.azurewebsites.net/home .

my code:

from flask import Flask
app = Flask(__name__)

@app.route("/home")
def home():
    return "Hello World a nice day!"

after deploy to azure, the site works well:

enter image description here