1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] What is the base exception for an invalid JWT in PyJWT?

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    According to the documentation for PyJWT, the class jwt.exceptions.InvalidTokenError is the base error when the decode method fails. However, the following code still breaks with different exceptions:

    try:
    jwt.decode(jwt_token, os.environ['SECRET'], algorithms="HS256")
    except jwt.exceptions.InvalidTokenError:
    pass


    My thinking was that since InvalidTokenError is the base error, this except block should catch all the other possible PyJWT errors such as InvalidSignatureError, DecodeError etc. My question is if there is a base error for PyJwt I could use. I know using except Exception is always an option but that's bad form so I'd like to avoid it if possible. Thanks!

    Continue reading...

Compartilhe esta Página