# Error deploying Python Flask template to cloud run

**URL:** <https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344>\
**Category:** General\
**Created:** [May 29, 2024, 7:23am UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344 "2024-05-29T07:23:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_Haugland](https://sea2.discourse-cdn.com/flex002/user_avatar/community.firebasestudio.dev/kenneth_haugland/32/303_2.png) [@Kenneth\_Haugland](https://community.firebasestudio.dev/u/Kenneth_Haugland)\
**Post date:** [May 29, 2024, 7:23am UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344/1 "2024-05-29T07:23:46Z")

</div>

I created a project with the python flask example and it runs fine in the editor. Great with the live preview.

I run the deploy command from the Project IDX menu to deploy to cloud run.  
When I navigate to the site:  
[https://idx-pythonflaskfinance-2610882-j4bn5fufta-nn.a.run.app/](https://idx-pythonflaskfinance-2610882-j4bn5fufta-nn.a.run.app/)

I get the message: Service Unavailable

I get this error in the logs:  
Traceback (most recent call last):  
File “/layers/google.python.pip/pip/lib/python3.12/site-packages/gunicorn/arbiter.py”, line 609, in spawn\_worker  
worker.init\_process()  
File “/layers/google.python.pip/pip/lib/python3.12/site-packages/gunicorn/workers/base.py”, line 134, in init\_process  
self.load\_wsgi()  
File “/layers/google.python.pip/pip/lib/python3.12/site-packages/gunicorn/workers/base.py”, line 146, in load\_wsgi  
self.wsgi = self.app.wsgi()

---

<div class="post-metadata">

**Author:** ![kirupa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.firebasestudio.dev/kirupa/32/4_2.png) [@kirupa](https://community.firebasestudio.dev/u/kirupa)\
**Post date:** [May 30, 2024, 4:09am UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344/2 "2024-05-30T04:09:57Z")

</div>

Hi @Kenneth_Haugland - does the deployment itself show any errors in the IDX output or terminal windows?

---

<div class="post-metadata">

**Author:** ![Alex](https://sea2.discourse-cdn.com/flex002/user_avatar/community.firebasestudio.dev/alex/32/218_2.png) [@Alex](https://community.firebasestudio.dev/u/Alex)\
**Post date:** [May 30, 2024, 4:06pm UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344/3 "2024-05-30T16:06:10Z")

</div>

Hi Kenneth, I’m trying to repro this issue. Looks like the server isn’t coming up. Can you help us by including the full logs please?

Also if possible, can you share your main.py please (or where app.run is defined)?

---

<div class="post-metadata">

**Author:** ![Kenneth\_Haugland](https://sea2.discourse-cdn.com/flex002/user_avatar/community.firebasestudio.dev/kenneth_haugland/32/303_2.png) [@Kenneth\_Haugland](https://community.firebasestudio.dev/u/Kenneth_Haugland)\
**Post date:** [June 3, 2024, 5:17pm UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344/4 "2024-06-03T17:17:02Z")

</div>

Sorry for the late answer:

I did no changes to the default template for flask application:  
main.py  
import os

from flask import Flask, send\_file

app = Flask( **name** )

@app.route(“/”)  
def index():  
return send\_file(‘index.html’)

def main():  
app.run(port=int(os.environ.get(‘PORT’, 80)))

if **name** == “ **main** ”:  
main()

* * *

Error in the Logs Explorer:  
Traceback (most recent call last):  
File “/layers/google.python.pip/pip/lib/python3.12/site-packages/gunicorn/arbiter.py”, line 609, in spawn\_worker  
worker.init\_process()  
File “/layers/google.python.pip/pip/lib/python3.12/site-packages/gunicorn/workers/base.py”, line 134, in init\_process  
self.load\_wsgi()  
File “/layers/google.python.pip/pip/lib/python3.12/site-packages/gunicorn/workers/base.py”, line 146, in load\_wsgi  
self.wsgi = self.app.wsgi()

---

<div class="post-metadata">

**Author:** ![Kenneth\_Haugland](https://sea2.discourse-cdn.com/flex002/user_avatar/community.firebasestudio.dev/kenneth_haugland/32/303_2.png) [@Kenneth\_Haugland](https://community.firebasestudio.dev/u/Kenneth_Haugland)\
**Post date:** [June 3, 2024, 5:25pm UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344/5 "2024-06-03T17:25:55Z")

</div>

No errors:  
Executing task: (set -o pipefail && gcloud run deploy idx-pythonflaskfinance-2610882 --source . --region northamerica-northeast1 --allow-unauthenticated 2\>&1 | tee /tmp/integrations.log)

source /home/user/pythonflaskfinance/.venv/bin/activate  
This command is equivalent to running `gcloud builds submit --pack image=[IMAGE] .` and `gcloud run deploy idx-pythonflaskfinance-2610882 --image [IMAGE]`

Building using Buildpacks and deploying container to Cloud Run service [idx-pythonflaskfinance-2610882] in project [stockoverflow2022] region [northamerica-northeast1]  
Building and deploying…  
Uploading sources…done  
Building Container…done  
Setting IAM Policy…done  
Creating Revision…done  
Routing traffic…done  
Done.  
Service [idx-pythonflaskfinance-2610882] revision [idx-pythonflaskfinance-2610882-00003-cfj] has been deployed and is serving 100 percent of traffic.  
Service URL: [https://idx-pythonflaskfinance-2610882-j4bn5fufta-nn.a.run.app](https://idx-pythonflaskfinance-2610882-j4bn5fufta-nn.a.run.app)

- Terminal will be reused by tasks, press any key to close it.

---

<div class="post-metadata">

**Author:** ![tcab](https://sea2.discourse-cdn.com/flex002/user_avatar/community.firebasestudio.dev/tcab/32/1912_2.png) [@tcab](https://community.firebasestudio.dev/u/tcab)\
**Post date:** [September 26, 2024, 10:32am UTC](https://community.firebasestudio.dev/t/error-deploying-python-flask-template-to-cloud-run/344/6 "2024-09-26T10:32:13Z")

</div>

I found creating a new Flask/Python project deployed ok but my old one didn’t. Seems the structure of the projects have changed - e.g. differences in projects’ `devserver.sh` were

```auto
python -m flask --app src/main run -p $PORT --debug
vs
python -m flask --app main run -p $PORT --debug

```

which doesn’t affect deployment but is evidence that the location of Python files in the template has changed over the last year or so. This might have something to do with it. Maybe the Docker deploy assumes a certain project structure - just speculating.
