Comments (4)
I found a temporary solution.
@https_fn.on_request()
def httpsflaskexample(req: https_fn.Request) -> https_fn.Response:
with app.request_context(req.environ):
g.request = req
return app.full_dispatch_request()
then use g.request in post function
@app.post("/api/test")
def stuff():
abc = g.request.get_data()
# abc= flask.request.get_json();
print("Jsondata:", abc)
# name = flask.request.args.get('name')
# print("name:", name)
data = {'Message': 'Hello World'}
return jsonify(data), 200
from firebase-functions-python.
I'm having the same problem when i call flask.request.get_data() in post
this is the traceback:
Traceback (most recent call last):
File "D:\MyDemo\functions\venv\lib\site-packages\flask\app.py", line 1508, in finalize_request
response = self.process_response(response)
File "D:\MyDemo\functions\venv\lib\site-packages\flask\app.py", line 2002, in process_response
response = self.ensure_sync(func)(response)
File "D:\MyDemo\functions\venv\lib\site-packages\functions_framework_init_.py", line 302, in read_request
flask.request.get_data()
File "D:\MyDemo\functions\venv\lib\site-packages\werkzeug\wrappers\request.py", line 420, in get_data
rv = self.stream.read()
File "D:\MyDemo\functions\venv\lib\site-packages\werkzeug\wsgi.py", line 577, in readall
data = self.read(1024 * 64)
File "D:\MyDemo\functions\venv\lib\site-packages\werkzeug\wsgi.py", line 562, in readinto
self.on_disconnect()
stuck in read and then timeout. if post with no body, it's fine.
By the way , i use the firebase emulators
from firebase-functions-python.
Hello @fzrcyc. I am doing a POST request to the URL both through the emulator and on a live deployment using the following command:
# Example for request to local emulator
curl -X POST http://127.0.0.1:5001/ff-test-74aeb/asia-south1/httpsflaskexample/api/test -d '{"key": "value"}' -H "Content-Type: application/json"
I get the following response back:
{"Message":"Hello World"}
This is the code I have in my main.py
file:
from firebase_functions import https_fn, options
import flask
from flask import jsonify
app = flask.Flask(__name__)
@app.post("/api/test")
def stuff():
abc = flask.request.get_data()
# abc= flask.request.get_json();
print("Jsondata:", abc)
# name = flask.request.args.get('name')
# print("name:", name)
data = {'Message': 'Hello World'}
return jsonify(data), 200
options.set_global_options(
max_instances=10, region=options.SupportedRegion.ASIA_SOUTH1)
@https_fn.on_request()
def httpsflaskexample(req: https_fn.Request) -> https_fn.Response:
with app.request_context(req.environ):
return app.full_dispatch_request()
Could you please provide a reproducible example for this issue as I cannot reproduce it using the code sample you provided?
from firebase-functions-python.
Same issue with request.json which calls get_json
@fzrcyc work around worked but very hacky lol
from firebase-functions-python.
Related Issues (20)
- Can not request firebase function by using Cloud Task HOT 25
- Sporadic datetime parse error HOT 9
- Unable to import logger HOT 6
- ModuleNotFoundError: No module named 'util' HOT 5
- Types are not exported HOT 9
- Parameterized configuration is not working HOT 1
- Missing retry in storage and firestore trigger decorators
- CORS Error on_call Cloud Function HOT 11
- logging library doesn't support Exceptions HOT 1
- Configure CPU-allocation, the run.googleapis.com/cpu-throttling boolean in Cloud Run HOT 2
- Firestore Emulator Cloud Trigger Issue with Write Operations HOT 1
- RetryConfig seems to be ignored on `@tasks_fn.on_task_dispatched` HOT 1
- auth-blocking-functions | Cannot extract event_type from identity_fn.AuthBlockingEvent HOT 1
- Container silently freezes on making a request to firestore if multiple requests were created before container starts HOT 2
- Cannot set invoker to public for HTTP request function HOT 3
- Firestore updates cause intermittent freezing of event triggers HOT 4
- Time data format error HOT 1
- Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 1463, in wsgi_app response = self.full_dispatch_request()
- KeyError: 'datacontenttype' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-functions-python.