from fastapi import FastAPI
from datetime import datetime
from ..models import Contact
from ..database import Database
app = FastAPI()
# Dependency
def get_db():
db = Database()
try:
yield db
finally:
db.disconnect()
@app.get("/contacts/", response_model=List[Contact])
async def get_contacts(address: int, start_time: datetime, end_time: datetime, duration: int, distance: int, db: Database = Depends(get_db)):
contacts = detect_contacts(db, address, start_time, end_time, duration, distance)
return contacts
I'm trying to get query parameters start_time and end_time as datetime values with timezone, based on ISO 8601 or RFC 3339. It works fine without timezone, for example, "2021-01-19 16:00:00" or "2021-01-19T16:00:00", but not with timezone, for example, "2021-01-19 16:00:00+05:00" or "2021-01-19T16:00:00+05:00", returning such error:
{
"detail": [
{
"loc": [
"query",
"start_time"
],
"msg": "invalid datetime format",
"type": "value_error.datetime"
}
]
}
FYI, it's explicitly mentioned in the documentation that it supports ISO 8601 format for datetime.datetime type: