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

Request body empty in FastAPI app that mounts Flask app #188

Closed
toxygene opened this issue May 7, 2021 · 1 comment
Closed

Request body empty in FastAPI app that mounts Flask app #188

toxygene opened this issue May 7, 2021 · 1 comment

Comments

@toxygene
Copy link

toxygene commented May 7, 2021

Using Serverless, I'm deploying a FastAPI app to Lambda. The FastAPI app simply mounts a Flask app with a single POST route. When I try to access the request data, it's empty (b'') instead of what was submitted.

from fastapi import FastAPI
from flask import Flask, request
from mangum import Mangum
from starlette.middleware.wsgi import WSGIMiddleware

flask_app = Flask(__name__)


@flask_app.route("/", methods=["POST"])
def hello_world():
    print(request.data)
    return "Hello, World!"


fastapi_app = FastAPI(debug=True)
fastapi_app.mount("/", WSGIMiddleware(flask_app))

handler = Mangum(fastapi_app)
service: fastapi-flask-test
frameworkVersion: '2'

provider:
  name: aws
  runtime: python3.8
  lambdaHashingVersion: 20201221

functions:
  hello:
    handler: handler.handler
    events:
      - http: ANY /
      - http: ANY {proxy+}

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: true
    dockerSsh: true
    usePoetry: true

If I run this code via uvicorn, the request body is correct.

import uvicorn

from handler import fastapi_app

uvicorn.run(fastapi_app)
@toxygene
Copy link
Author

toxygene commented May 8, 2021

After further investigation, this appears to be a duplicate of #143.

@toxygene toxygene closed this as completed May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant