Reputation: 611
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName fastapi.example.com
ServerAlias fastapi.example.com
DocumentRoot /var/www/fastapi
ErrorLog ${APACHE_LOG_DIR}/fastapi_error.log
CustomLog ${APACHE_LOG_DIR}/fastapi_access.log combined
WSGIScriptAlias / /var/www/fastapi/main.wsgi
<Directory "/var/www/fastapi">
AllowOverride All
</Directory>
</VirtualHost>
and created main.wsgi and main.py files.
main.wsgi
#! /usr/bin/python3.7
import logging
import sys
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/fastapi/')
from main import app as application
application.secret_key = 'alibaba'
main.py
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
When i am trying to access the web, I got the 500 Internal server Error with the following log in fastapi_access.log
mod_wsgi (pid=24946): Exception occurred processing WSGI script '/var/www/fastapi/main.wsgi'.
TypeError: __call__() missing 1 required positional argument: 'send'
Could you please advice, how can I fix this problem and what am I doing wrong?
Thanks in advance.Upvotes: 6
Views: 4044
Reputation: 20598
WSGI servers is not compatible with FastAPI, FastAPI only runs in ASGI server, gunicorn and all the other WSGI servers just implements PEP Standards with ASGI workers in depth they still work as ASGI with the workers.
Upvotes: 7