Search code examples
pythondigital-oceanfastapilinodeuvicorn

Invalid HTTP method in Traceback: Uvicorn


I am using uvicorn 0.11.8 and fastapi 0.61.1. My application is hosted in VPS. When I run the app in local server, such error is not reproducible. It shows correct message 404 Not found for methods not available but I couldn't figure out what is causing this issue in VPS (error in Traceback). enter image description here


Solution

  • I was getting the same arcane WARNING: Invalid HTTP request received. error with an unhelpful stack trace. I tried all of the environment variable tweaks recommended and none worked (see FastAPI issue #680, uvicorn issue #441).

    My issue was that when I was calling my FastAPI microservice I was using https when my microservice did not have HTTPS support. I changed the url from https to http and it started working as expected.

    Note that if your service requires HTTPS support you can add HTTPS support.

    Also, see the similar post AWS ec2 + uvicorn + fastapi, i get uvicorn error.