Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

574
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda