Python Flask Azure Linux WebApp fails with AttributeError: module 'enum' has no attribute 'IntFlag'

Ashish Kesarkar 61 Reputation points
2021-07-15T12:37:09.69+00:00

Python Flask Azure Linux WebApp fails with below error

Source Code :

from flask import Flask, request
from kiteconnect import KiteConnect

app = Flask(__name__)

@app.route('/')
def index():
    Zerodha_API_KEY = "XXXXXXXXXX"
    Zerodha_API_SECRET= "XXXXXXXXXXX"
    Zerodha_Access_Token= "XXXXXXXXXXX"
    kite = KiteConnect(api_key=Zerodha_API_KEY)
    kite.set_access_token(Zerodha_Access_Token)
    data = kite.orders()
    print(data)
    return str(data)

Error :
2021-07-15T11:12:09.280237068Z 2021-07-15T11:12:09.280292471Z _____ 2021-07-15T11:12:09.280304271Z / _ \ __________ _________ ____ 2021-07-15T11:12:09.280311872Z / /_\ \___ / | \_ __ \_/ __ \ 2021-07-15T11:12:09.280319472Z / | \/ /| | /| | \/\ ___/ 2021-07-15T11:12:09.280326672Z \____|__ /_____ \____/ |__| \___ > 2021-07-15T11:12:09.280334173Z \/ \/ \/ 2021-07-15T11:12:09.280341373Z 2021-07-15T11:12:09.280348073Z A P P S E R V I C E O N L I N U X 2021-07-15T11:12:09.280354874Z 2021-07-15T11:12:09.280361474Z Documentation: http://aka.ms/webapp-linux 2021-07-15T11:12:09.280368174Z Python 3.8.6 2021-07-15T11:12:09.280374875Z Note: Any data outside '/home' is not persisted 2021-07-15T11:12:09.654320473Z Starting OpenBSD Secure Shell server: sshd. 2021-07-15T11:12:09.739608672Z App Command Line not configured, will attempt auto-detect 2021-07-15T11:12:09.740706500Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite 2021-07-15T11:12:09.871149910Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it... 2021-07-15T11:12:09.881601967Z Build Operation ID: |8ufRzjfGT4Q=.9903ac7b_ 2021-07-15T11:12:09.890669690Z Oryx Version: 0.2.20210420.1, Commit: 85c6e9278aae3980b86cb1d520aaad532c814ed7, ReleaseTagName: 20210420.1 2021-07-15T11:12:09.891252705Z Output is compressed. Extracting it... 2021-07-15T11:12:09.895295404Z Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8d94707cb81be1f'... 2021-07-15T11:12:14.577736859Z App path is set to '/tmp/8d94707cb81be1f' 2021-07-15T11:12:16.276763516Z Detected an app based on Flask 2021-07-15T11:12:16.278429174Z Generating gunicorncommand for 'app:app' 2021-07-15T11:12:16.836063591Z Writing output script to '/opt/startup/startup.sh' 2021-07-15T11:12:17.568867477Z Using packages from virtual environment antenv located at /tmp/8d94707cb81be1f/antenv. 2021-07-15T11:12:17.569943514Z Updated PYTHONPATH to ':/tmp/8d94707cb81be1f/antenv/lib/python3.8/site-packages' 2021-07-15T11:12:17.674962252Z Traceback (most recent call last): 2021-07-15T11:12:17.675003253Z File "/opt/python/3.8.6/bin/gunicorn", line 3, in <module> 2021-07-15T11:12:17.675027254Z import re 2021-07-15T11:12:17.675036154Z File "/opt/python/3.8.6/lib/python3.8/re.py", line 145, in <module> 2021-07-15T11:12:17.675044155Z class RegexFlag(enum.IntFlag): 2021-07-15T11:12:17.675051755Z AttributeError: module 'enum' has no attribute 'IntFlag' 2021-07-15T11:12:25.447Z ERROR - Container rocketzerodha_0_7bea6f30 for site rocketzerodha has exited, failing site start 2021-07-15T11:12:25.461Z ERROR - Container rocketzerodha_0_7bea6f30 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging. 2021-07-15T11:12:25.475Z INFO - Stopping site rocketzerodha because it failed during startup.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,758 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 28,106 Reputation points Microsoft Employee
    2021-07-15T17:43:09.247+00:00

    Hi @Ashish Kesarkar ,

    Make sure SCM_DO_BUILD_DURING_DEPLOYMENT application setting is set to 1 or true; see https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#customize-build-automation.

       az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings SCM_DO_BUILD_DURING_DEPLOYMENT ="true"  
    

    EDIT: If you're using a yaml script to deploy your app, you can add your settings via this sample yaml script.

       - name: Disable static collection and set migration command on App Service  
         uses: Azure/appservice-settings@v1  
         with:    
           app-name: ${{ env.WEBAPP_NAME }}  
           app-settings-json: '[{ "name": "DISABLE_COLLECTSTATIC", "value": "true" }, { "name": "POST_BUILD_COMMAND",  "value": "python manage.py makemigrations && python manage.py migrate" }, { "name": "SCM_DO_BUILD_DURING_DEPLOYMENT", "value": "true" }, { "name": "DJANGO_ENV", "value": "production"}]'  
    

    source: https://azure.github.io/AppService/2020/12/11/cicd-for-python-apps.html


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.