Search code examples
pythondockerpipjwtattributeerror

AttributeError: module 'jwt.algorithms' has no attribute 'hashes'


I try to run the following script in a Python virtual environment by having pyjwt installed with pip3 install -U pyjwt as per suggested and it works

import requests
from requests_oauthlib import OAuth1
from oauthlib.oauth1 import SIGNATURE_RSA

headerauth = OAuth1(client_key, rsa_key, signature_type="auth_header", signature_method=SIGNATURE_RSA)
r = requests.get(url, auth=headerauth)

However, it's throwing an error when I try to run the local Docker image

AttributeError: module 'jwt.algorithms' has no attribute 'hashes'

The versions stated in Pipfile are same as those in Python virtual environment

[packages]
pyjwt = ">=2.8.0"
requests-oauthlib = ">=1.3.1"

Solution

  • Installing cryptography should solve this issue:

    pip install -U cryptography