Azure / Azure/app-service-linux-docs

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

Open
#248 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
150
Forks
90
Avg merge
2m
Merged PRs (30d)
1

Description

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://.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 "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/home/site/wwwroot/app.py", line 2, in
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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.