question

AshishKesarkar avatar image
0 Votes"
AshishKesarkar asked ryanchill edited

Python App does not work once ported on Linux App Service WebApp

Hi,

I have successfully executed the Python app using Visual Studio Code on my laptop.

I am importing following in Python App.
from types import CodeType
from flask import Flask, request
from fyers_api import accessToken
from fyers_api import fyersModel
from azure.data.tables import TableServiceClient
from azure.data.tables import TableClient
import requests

Code Repository is on Azure DevOps and I have built the Pipeline to push the Build on Linux App Service Web Application.

It gives following Error :

:( Application Error
If you are the application administrator, you can access the diagnostic resources.

I got following log in the App Service Log. I need help to fix this.

/home/LogFiles/2021_04_01_lw0sdlwk000005_default_docker.log (https://rockettokensaverapp.scm.azurewebsites.net/api/vfs/LogFiles/2021_04_01_lw0sdlwk000005_default_docker.log)
2021-04-01T15:18:48.321394582Z Error: While importing "app", an ImportError was raised:
2021-04-01T15:18:48.321410882Z
2021-04-01T15:18:48.321415782Z Traceback (most recent call last):
2021-04-01T15:18:48.321433682Z File "/opt/python/3.8.6/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app
2021-04-01T15:18:48.321489182Z import(module_name)
2021-04-01T15:18:48.321495482Z File "/home/site/wwwroot/app.py", line 4, in <module>
2021-04-01T15:18:48.321499682Z from fyers_api import accessToken
2021-04-01T15:18:48.321503282Z ModuleNotFoundError: No module named 'fyers_api'
2021-04-01T15:18:48.321506982Z
/home/LogFiles/2021_04_01_lw0sdlwk000005_docker.log (https://rockettokensaverapp.scm.azurewebsites.net/api/vfs/LogFiles/2021_04_01_lw0sdlwk000005_docker.log)
2021-04-01T15:18:36.243Z INFO - Starting container for site
2021-04-01T15:18:36.243Z INFO - docker run -d -p 9262:8000 --name rockettokensaverapp_0_1e510670 -e WEBSITE_SITE_NAME=RocketTokenSaverApp -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=rockettokensaverapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=a49e0f8ab240b39b4907e637cfb2809cc16b82d0b7fafe7739b53cea268e3195 appsvc/python:3.8_20201229.1
2021-04-01T15:18:36.243Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2021-04-01T15:18:39.289Z INFO - Initiating warmup request to container rockettokensaverapp_0_1e510670 for site rockettokensaverapp
2021-04-01T15:18:49.520Z ERROR - Container rockettokensaverapp_0_1e510670 for site rockettokensaverapp has exited, failing site start
2021-04-01T15:18:49.526Z ERROR - Container rockettokensaverapp_0_1e510670 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2021-04-01T15:18:49.653Z INFO - Stopping site rockettokensaverapp because it failed during startup.
/home/LogFiles/webssh/pm2.log (https://rockettokensaverapp.scm.azurewebsites.net/api/vfs/LogFiles/webssh/pm2.log)
Ending Log Tail of existing logs ---




azure-webapps-content-deployment
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ryanchill avatar image
0 Votes"
ryanchill answered ryanchill commented

Hi @AshishKesarkar,

Make sure you have added SCM_DO_BUILD_DURING_DEPLOYMENT to your application settings and have it set to true. This setting ensures that the virtual environment in the App Service is correctly installing your dependencies. See https://azure.github.io/AppService/2020/12/11/cicd-for-python-apps.html for more info.

Regards,
Ryan


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Dear Ryan,

You are amazing!
Three weeks of hardship you have solved in just one post!

You have saved me! This will help me to build my own Algo Trading Platfrom on Azure App Service.

By any chance, if you come to India, full travel on me! Will be glad to host you at my place.

Cheers!
Ashish Kesarkar
Mumbai, India

1 Vote 1 ·

Glad to have helped Ashish!!

Regards,
Ryan

0 Votes 0 ·
AshishKesarkar avatar image
0 Votes"
AshishKesarkar answered AshishKesarkar commented

Tried removing Fyers API from the code and kept Azure Data tables.

Now error has shifted to Azure Data Tables.
Below is the log.

2021-04-02T14:45:11.036846457Z
2021-04-02T14:45:11.037019758Z
2021-04-02T14:45:11.037029958Z /
\
2021-04-02T14:45:11.037034558Z / /
\ _ / | _ _/ \
2021-04-02T14:45:11.037039058Z / | \/ /| | /| | \/\
/
2021-04-02T14:45:11.037043958Z _
| / _/ || ___ >
2021-04-02T14:45:11.037048358Z \/ \/ \/
2021-04-02T14:45:11.037052858Z
2021-04-02T14:45:11.037056858Z A P P S E R V I C E O N L I N U X
2021-04-02T14:45:11.037060858Z
2021-04-02T14:45:11.037064758Z Documentation: http://aka.ms/webapp-linux
2021-04-02T14:45:11.037078358Z Python 3.8.6
2021-04-02T14:45:11.037083958Z Note: Any data outside '/home' is not persisted
2021-04-02T14:45:11.727122806Z Starting OpenBSD Secure Shell server: sshd.
2021-04-02T14:45:11.834760392Z App Command Line not configured, will attempt auto-detect
2021-04-02T14:45:11.835888893Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite
2021-04-02T14:45:12.112835013Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2021-04-02T14:45:12.112865313Z Could not find operation ID in manifest. Generating an operation id...
2021-04-02T14:45:12.112871713Z Build Operation ID: 474cb91c-8b62-46ec-97be-1789dd6410ca
2021-04-02T14:45:14.778669530Z Oryx Version: 0.2.20210225.2, Commit: f7b557f29a83aa078cc94c0056e7337c07f14271, ReleaseTagName: 20210225.2
2021-04-02T14:45:15.479130887Z Detected an app based on Flask
2021-04-02T14:45:15.480798989Z Generating gunicorn command for 'app:app'
2021-04-02T14:45:16.243982755Z Writing output script to '/opt/startup/startup.sh'
2021-04-02T14:45:16.767427785Z Using packages from virtual environment antenv located at /home/site/wwwroot/antenv.
2021-04-02T14:45:16.767479185Z Updated PYTHONPATH to ':/home/site/wwwroot/antenv/lib/python3.8/site-packages'
2021-04-02T14:45:17.737333539Z [2021-04-02 14:45:17 +0000] [36] [INFO] Starting gunicorn 20.0.4
2021-04-02T14:45:17.745903151Z [2021-04-02 14:45:17 +0000] [36] [INFO] Listening at: http://0.0.0.0:8000 (36)
2021-04-02T14:45:17.746717352Z [2021-04-02 14:45:17 +0000] [36] [INFO] Using worker: sync
2021-04-02T14:45:17.756998766Z [2021-04-02 14:45:17 +0000] [38] [INFO] Booting worker with pid: 38
2021-04-02T14:45:18.348277291Z [2021-04-02 14:45:18 +0000] [38] [ERROR] Exception in worker process
2021-04-02T14:45:18.348333091Z Traceback (most recent call last):
2021-04-02T14:45:18.348338891Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-04-02T14:45:18.348343591Z worker.init_process()
2021-04-02T14:45:18.348347691Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
2021-04-02T14:45:18.348363691Z self.load_wsgi()
2021-04-02T14:45:18.348368091Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2021-04-02T14:45:18.348381591Z self.wsgi = self.app.wsgi()
2021-04-02T14:45:18.348385591Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-04-02T14:45:18.348389691Z self.callable = self.load()
2021-04-02T14:45:18.348393591Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2021-04-02T14:45:18.348397791Z return self.load_wsgiapp()
2021-04-02T14:45:18.348401691Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2021-04-02T14:45:18.348405791Z return util.import_app(self.app_uri)
2021-04-02T14:45:18.348410291Z File "/opt/python/3.8.6/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
2021-04-02T14:45:18.348414391Z mod = importlib.import_module(module)
2021-04-02T14:45:18.348418291Z File "/opt/python/3.8.6/lib/python3.8/importlib/init.py", line 127, in import_module
2021-04-02T14:45:18.348422391Z return _bootstrap._gcd_import(name[level:], package, level)
2021-04-02T14:45:18.348426391Z File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-04-02T14:45:18.348469591Z File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-04-02T14:45:18.348473891Z File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-04-02T14:45:18.348478091Z File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-04-02T14:45:18.348482191Z File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2021-04-02T14:45:18.348486291Z File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-04-02T14:45:18.348490391Z File "/home/site/wwwroot/app.py", line 7, in <module>
2021-04-02T14:45:18.348494491Z from azure.data.tables import TableServiceClient
2021-04-02T14:45:18.348498491Z ModuleNotFoundError: No module named 'azure'
2021-04-02T14:45:18.349457293Z [2021-04-02 14:45:18 +0000] [38] [INFO] Worker exiting (pid: 38)
2021-04-02T14:45:18.498020000Z [2021-04-02 14:45:18 +0000] [36] [INFO] Shutting down: Master
2021-04-02T14:45:18.506669812Z [2021-04-02 14:45:18 +0000] [36] [INFO] Reason: Worker failed to boot.
2021-04-02T14:45:19.953Z ERROR - Container rockettokensaverapp_0_86e409f3 for site rockettokensaverapp has exited, failing site start
2021-04-02T14:45:19.956Z ERROR - Container rockettokensaverapp_0_86e409f3 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2021-04-02T14:45:19.963Z INFO - Stopping site rockettokensaverapp because it failed during startup.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AshishKesarkar, do you see any errors around the azure module when you access the deployment logs?


0 Votes 0 ·

Hey Ryan,

Not now. Everything is running smooth after adding SCM_DO_BUILD_DURING_DEPLOYMENT to application settings.

1 Vote 1 ·