Home > front end >  TypeError when running http functions_framework in docker container
TypeError when running http functions_framework in docker container

Time:01-25

I am trying to run functions_framework in a docker container and following Google's official link: enter image description here Here's my code:

from flask import escape
import functions_framework


@functions_framework.http
def hello_http(request):
    request_json = request.get_json(silent=True)
    request_args = request.args
    if request_json and "name" in request_json:
        name = request_json["name"]
    elif request_args and "name" in request_args:
        name = request_args["name"]
    else:
        name = "World"
    return "Hello {}!".format(escape(name))

I'm sending a post request here: http://localhost:9080/hello_http/

CodePudding user response:

The "TypeError: The view function did not return a valid response" error typically occurs when using the Flask web framework in Python and indicates that the view function (i.e., the function that handles a request and returns a response) did not return a valid response object. This can happen if the view function returns something other than a response object, such as a string. You can have a look at this example in the Link.

To fix this error, you should make sure that the view function returns a valid response object, such as an instance of the Response class from the flask module

Alternatively, you can use the make_response function from the flask module to create a response object.

You also need to check if the package is installed correctly in the Docker container which is added in the requirement.txt or in the Dockerfile.

Make sure that your package is up to date with the latest version that is installed.

Also have a look at this thread1 and thread2 which might be helpful.

  • Related