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

Ashish Kesarkar 61 Reputation points
2021-04-01T15:26:56.157+00:00

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 App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,256 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 29,651 Reputation points Microsoft Employee
    2021-04-02T15:08:53.4+00:00

    Hi @Ashish Kesarkar ,

    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


1 additional answer

Sort by: Most helpful
  1. Ashish Kesarkar 61 Reputation points
    2021-04-02T14:59:15.693+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.