JWTValidationException - utf-8' codec can't decode bytes

I got the following error on python when access_token passed to “verify_access_token”. Does anyone know how to fix this error?

from okta_jwt_verifier import JWTVerifier

def authenticate(self, request):
    access_token = request.META.get('HTTP_AUTHORIZATION')
    loop = asyncio.new_event_loop()
    jwt_verifier = JWTVerifier(issuer='https://devtest.okta.com/oauth2/default', 
    client_id='12345', audience='api://default')
    loop.run_until_complete(jwt_verifier.verify_access_token(access_token))

ERROR

JWTValidationException
Invalid header string: ‘utf-8’ codec can’t decode bytes in position 1-2: invalid continuation byte

Request Method: GET
Request URL: http://127.0.0.1:8000/getdata/
Django Version: 2.2.10
Exception Type: JWTValidationException
Exception Value: Invalid header string: ‘utf-8’ codec can’t decode bytes in position 1-2: invalid continuation byte
Exception Location: C:\WEB\project\pyenv\lib\site-packages\okta_jwt_verifier\jwt_verifier.py in verify_access_token, line 101

hey @shahinkar could you check if your access_token object has “Bearer” prepended to it? If so, remove it and see if that helps.

# This should just give you the access token.
access_token = request.META.get('HTTP_AUTHORIZATION', '').replace('Bearer', '').strip()
1 Like

Fixed, thanks for your help!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.