Code Monkey home page Code Monkey logo

Comments (4)

fzrcyc avatar fzrcyc commented on June 20, 2024 1

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.

fzrcyc avatar fzrcyc commented on June 20, 2024

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.

exaby73 avatar exaby73 commented on June 20, 2024

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.

Enlumis avatar Enlumis commented on June 20, 2024

Same issue with request.json which calls get_json
@fzrcyc work around worked but very hacky lol

from firebase-functions-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.