Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

583
Views
fastapi get header parameter is none in basemodel use Header cant get token but in function its ok why?

in basemodel use Header cant get token but in function its ok why?

   class Test(BaseModel):
        name: str
        token: str= Header(None)

def login(t: Test):
    print(t.dict())
    return 'test'

output  {'name': '123', 'token': None} 

if i do this is ok

def login(t: Test,token: str= Header(None)):
        print(t.dict(),token)
        return 'test'
    
    output  {'name': '123', 'token': None} 123456

who can help me plz !

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The Pydantic model here represents the validation of the request payload.

The values mentioned in the "Test" model should be available in request payload. Since the header is not the payload, we cannot use that in Basemodel.

Yet you can use that in api function. When you call the api, then the request params can be used in the function. So, it is possible to use this

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!