-
Notifications
You must be signed in to change notification settings - Fork 3.9k
-
I have the following main.py firebase function which I am trying to deploy using firebase deploy But when I curl the firebase endpoint I get a 404 error:
curl -v https://us-central1-<project-id>.cloudfunctions.net/test
Here is the function I deployed:
from firebase_admin import initialize_app, db
from firebase_functions import https_fn
import flask
initialize_app()
app = flask.Flask(__name__)
print("TEST APP")
@app.get('/test')
def hello_world():
print('Hello World')
return 'Hello, Firebase Cloud Functions with Python'
When I run the function locally by entering this command flask --app main run I am able to hit this endpoint, but not when I curl the firebase endpoint.
However, when I go to the Google Cloud Console, no functions appear. I am thinking that there must be a problem with the deployment. When I type: firebase -P staging deploy --only functions
I get the following output:
(node:25815) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
=== Deploying to '<progject-id>'...
i deploying functions
i functions: preparing codebase cancer-hacked for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase cancer-hacked to determine what to deploy
* Serving Flask app 'serving'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:8081
Press CTRL+C to quit
127.0.0.1 - - [15/Nov/2024 14:55:25] "GET /__/functions.yaml HTTP/1.1" 200 -
127.0.0.1 - - [15/Nov/2024 14:55:25] "GET /__/quitquitquit HTTP/1.1" 200 -
/bin/sh: line 1: 25820 Terminated: 15 python3.11 "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/firebase_functions/private/serving.py"
i functions: cleaning up build files...
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/<progject-id>/overview
I have done the following commands:
pip install -r requirements.txt
firebase init functions
My requirements.txt file has the following:
Flask
firebase-admin
firebase-functions
And I have the following installed libraires by running pip3 list are:
Package Version
------------------------ ---------
blinker 1.9.0
CacheControl 0.14.1
cachetools 5.5.0
certifi 2024年8月30日
cffi 1.17.1
charset-normalizer 3.4.0
click 8.1.7
cloudevents 1.9.0
cryptography 43.0.3
deprecation 2.1.0
firebase-admin 6.6.0
firebase-functions 0.1.2
Flask 3.1.0
Flask-Cors 5.0.0
functions-framework 3.8.2
google-api-core 2.23.0
google-api-python-client 2.153.0
google-auth 2.36.0
google-auth-httplib2 0.2.0
google-cloud-core 2.4.1
google-cloud-firestore 2.19.0
google-cloud-storage 2.18.2
google-crc32c 1.6.0
google-events 0.13.0
google-resumable-media 2.7.2
googleapis-common-protos 1.66.0
grpcio 1.67.1
grpcio-status 1.67.1
gunicorn 23.0.0
httplib2 0.22.0
idna 3.10
itsdangerous 2.2.0
Jinja2 3.1.4
MarkupSafe 3.0.2
msgpack 1.1.0
packaging 24.2
pip 24.0
proto-plus 1.25.0
protobuf 5.28.3
pyasn1 0.6.1
pyasn1_modules 0.4.1
pycparser 2.22
PyJWT 2.9.0
pyparsing 3.2.0
PyYAML 6.0.2
requests 2.32.3
rsa 4.9
setuptools 65.5.0
typing_extensions 4.12.2
uritemplate 4.1.1
urllib3 2.2.3
watchdog 6.0.0
Werkzeug 3.1.3
I am running python version 3.11.9. Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions
I found what I was missing to get the firebase cloud function working using python's Flask library. I had to register the flask app to use https_fn wrapper. Here is the code which now works when doing a firebase deploy
import firebase_admin
from firebase_admin import credentials, firestore
from flask import Flask, request
from firebase_functions import https_fn
from cancer import get_cancer
# Initialize Firebase Admin SDK
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
app = Flask(__name__)
@app.route('/test', methods=['GET'])
def test():
print("Hello World")
return "Hello World"
# Main entry point for Fireba...Replies: 1 comment
-
I found what I was missing to get the firebase cloud function working using python's Flask library. I had to register the flask app to use https_fn wrapper. Here is the code which now works when doing a firebase deploy
import firebase_admin
from firebase_admin import credentials, firestore
from flask import Flask, request
from firebase_functions import https_fn
from cancer import get_cancer
# Initialize Firebase Admin SDK
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
app = Flask(__name__)
@app.route('/test', methods=['GET'])
def test():
print("Hello World")
return "Hello World"
# Main entry point for Firebase Functions
#firebase_function = functions.https.on_request(app)
@https_fn.on_request()
def functions(req: https_fn.Request) -> https_fn.Response:
with app.request_context(req.environ):
return app.full_dispatch_request()
You can find more documentaiton in the following firebase docs:
https://firebase.google.com/docs/functions/http-events?gen=2nd
You can then access the test endpoint by going to curl -v https://us-central1-<project-id>.cloudfunctions.net/functions/test
Beta Was this translation helpful? Give feedback.