I am making a module for registration, authentication and authorization. The registration process is divided into 2 stages (2 handler functions), the problem I have with the second stage is that through “Postman”, the request works correctly, but through FastAPI documentation it gives an error that the header “Authorization” is not passed, here is the code:
@app_reg.post("/confirm")
async def confirm(data: CodeConfirm,
authorization: str = Header(...),
) -> JSONResponse:
"""
Processing of the form for entering the registration confirmation code.
Args:
authorization: Caption Authorization
code: Code from the form.
Returns:
JSONResponse: Code Validation Result.
- 200: Successful validation, returns a success message.
- 422: Validation error, returns an error message.
- 400: Validation error, returns an appropriate message.
Notes:
- Receives data from session, sends to backend, on successful
response from the backend, clears the session.
"""
try:
user_data = get_redis_via_token(authorization, SECRET_KEY_REGISTRATION)
if isinstance(user_data, JSONResponse):
return user_data
email = user_data.get('email')
login = user_data.get('login')
password = user_data.get('password')
verification_code = user_data.get('code')
except Exception as e:
return JSONResponse(content={"message": str(e)}, status_code=400)
result = await Registration.confirm_register(
email, login, password, data.code, verification_code)
if result['status_code'] == 200:
redis_client.delete(f"login:{login}")
return JSONResponse(content={"message": result["message"]},
status_code=200)
else:
return JSONResponse(content={"message": result["message"]},
status_code=400)
And here is the error itself with code 422:
{
"detail": [
{
"type": "missing",
"loc": [
"header",
"authorization"
],
"msg": "Field required",
"input": null
}
]
}
I tried adding an alias, I tried actually making a request through “Postman” (in it the request works correctly).
1