Skip to content

Issue with Python Flask App Deployment to Azure App Service During Zip Deployment #248

@chirucodes

Description

@chirucodes

Hi everyone,

I'm facing an issue with deploying my Python Flask app to Azure App Service(Python 3.9) using zip deployment. Below are the details:

Directory structure:

.
|---app.py    
|---requirements.txt

Working Code:

app.py:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello, Azure!--1"

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

requirements.txt:

Flask==3.1.0

Non-Working Code:

app.py:

from flask import Flask
import openai

app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello, Azure!--2"

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

requirements.txt:

Flask==3.1.0
openai==1.57.1

Steps for deploying:

Create zip:

  • Open the directory in file explorer
  • Select the above files (app.py and requirements.txt)
  • Right click on file app.py
  • Compress to -> ZIP File

Command to deploy into Azure app service:

curl -k -v -X POST -H 'Content-Type: application/zip' -u "<$app_service_user>:<60character_length_userPWD>" --data-binary @app.zip https://<appservicename>.scm.dev001.ase.frk.com/api/zipdeploy

Error in the API log stream:

Site's appCommandLine: gunicorn --bind=0.0.0.0:8000 app:app
Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'gunicorn --bind=0.0.0.0:8000 app:app'
Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
Could not find operation ID in manifest. Generating an operation id...
Build Operation ID: c9b33d68-8d6d-4326-9b08-257fe923d135
Oryx Version: 0.2.20240619.2, Commit: cf006407a02b225f59dccd677986973c7889aa50, ReleaseTagName: 20240619.2
Writing output script to '/opt/startup/startup.sh'
WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.


Booting worker with pid: 1075
[1075] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
  worker.init_process()
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
  self.load_wsgi()
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
  self.wsgi = self.app.wsgi()
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
  self.callable = self.load()
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
  return self.load_wsgiapp()
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
  return util.import_app(self.app_uri)
File "/opt/python/3.9.19/lib/python3.9/site-packages/gunicorn/util.py", line 371, in import_app
  mod = importlib.import_module(module)
File "/opt/python/3.9.19/lib/python3.9/importlib/__init__.py", line 127, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/site/wwwroot/app.py", line 2, in <module>
    import openai
ModuleNotFoundError: No module named 'openai'
[1075] [INFO] Worker exiting (pid: 1075)
[1064] [ERROR] Worker (pid:1075) exited with code 3
[1064] [ERROR] Shutting down: Master
[1064] [ERROR] Reason: Worker failed to boot.

I've verified that the code works locally, but it fails when deployed to Azure App Service. Any insights or suggestions on what might be causing this issue would be greatly appreciated!

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions