Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase use flask route get "ECONNRESET" ,The restful api never response until 60s timeout #159

Open
xactester opened this issue Nov 13, 2023 · 4 comments
Labels
waiting for customer response Issue is on hold awaiting more information from OP

Comments

@xactester
Copy link

@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
@https_fn.on_request()
def httpsflaskexample(req: https_fn.Request) -> https_fn.Response:
    with app.request_context(req.environ):
        return app.full_dispatch_request()

A sample like firebase_documents
If i remove request.get_data(), It will be ok.

@fzrcyc
Copy link

fzrcyc commented Nov 14, 2023

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

@fzrcyc
Copy link

fzrcyc commented Nov 16, 2023

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

@exaby73
Copy link
Contributor

exaby73 commented Jan 15, 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?

@exaby73 exaby73 added the waiting for customer response Issue is on hold awaiting more information from OP label Jan 15, 2024
@Enlumis
Copy link

Enlumis commented Feb 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for customer response Issue is on hold awaiting more information from OP
Projects
None yet
Development

No branches or pull requests

4 participants