pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.94k stars 860 forks source link

Can't use OAuth to authenticate (No module named jwt.algorithms from oauthlib) #1068

Open bytefluxio opened 3 years ago

bytefluxio commented 3 years ago

Description: Using the following short snippet raises a ModuleNotFoundError: No module named 'jwt.algorthms'

oauth = {
                'access_token': token,
                'access_token_secret': token_secret,
                'consumer_key': consumer_key,
                'key_cert': key_cert_data
            }
            JIRA(server_url, oauth=oauth)

Instead the contructor throws an exception. What is not shown in the exception is everthing between me calling the constructor and oauthlib's signature.py.

client.py: line 506: si = self.server_info() line 2551: j = self._get_json("serverInfo") line 3139: r = self._session.get(url, params=params)

resilientsession.py: line 172: return self.__verb("GET", url, **kwargs) line 143: response = method(url, timeout=self.timeout, **kwargs) <-- throws exception

Stack Trace

Traceback (most recent call last):
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\jira\resilientsession.py", line 143, in __verb
    response = method(url, timeout=self.timeout, **kwargs)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 456, in prepare_request
    p.prepare(
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 320, in prepare
    self.prepare_auth(auth, url)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 551, in prepare_auth
    r = auth(self)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\requests_oauthlib\oauth1_auth.py", line 108, in __call__
    r.url, headers, _ = self.client.sign(
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\__init__.py", line 351, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\__init__.py", line 186, in get_oauth_signature
    sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\signature.py", line 742, in sign_rsa_sha1_with_client
    return _sign_rsa('SHA-1', sig_base_str, client.rsa_key)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\signature.py", line 617, in _sign_rsa
    alg = _get_jwt_rsa_algorithm(hash_algorithm_name)
  File "C:\Users\rwestman\AppData\Local\Programs\Python\Python39\lib\site-packages\oauthlib\oauth1\rfc5849\signature.py", line 562, in _get_jwt_rsa_algorithm
    import jwt.algorithms as jwt_algorithms
ModuleNotFoundError: No module named 'jwt.algorithms'

Version Information Type of Jira instance:

bytefluxio commented 3 years ago

Might be related to the requirements.txt change last month with 37055fda603b979527f4a50c3d883a6d1ed663c9

Might also be related to #1069

RCFans commented 3 years ago

run pip install PyJWT could fix it.

Package Version


certifi 2021.5.30 cffi 1.14.5 chardet 4.0.0 cryptography 3.4.7 defusedxml 0.7.1 idna 2.10 importlib-metadata 4.6.0 jira 3.0.1 keyring 23.0.1 oauthlib 3.1.1 pip 20.1.1 pycparser 2.20 PyJWT 2.1.0 requests 2.25.1 requests-oauthlib 1.3.0 requests-toolbelt 0.9.1 setuptools 47.1.0 typing-extensions 3.10.0.0 urllib3 1.26.6 zipp 3.4.1

I don't think this issues is in Jira, it should be fixed in oauthlib.

studioj commented 3 years ago

quick SO search showed this https://stackoverflow.com/a/68277540/2559785

can you check and if fixed close the issue?