question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: No module named jwt.algorithms

See original GitHub issue

After installing pyxero 0.7.0 via pip, and attempting to connect to a Private Application, I get the following ImportError:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/xero/manager.py", line 177, in wrapper
    params=params, cert=cert, timeout=timeout)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 60, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 443, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 374, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib/python2.7/dist-packages/requests/models.py", line 308, in prepare
    self.prepare_auth(auth, url)
  File "/usr/lib/python2.7/dist-packages/requests/models.py", line 492, in prepare_auth
    r = auth(self)
  File "/usr/local/lib/python2.7/dist-packages/requests_oauthlib/oauth1_auth.py", line 87, in __call__
    unicode(r.url), unicode(r.method), None, r.headers)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 313, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth1/rfc5849/__init__.py", line 150, in get_oauth_signature
    sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth1/rfc5849/signature.py", line 505, in sign_rsa_sha1_with_client
    return sign_rsa_sha1(base_string, client.rsa_key)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth1/rfc5849/signature.py", line 496, in sign_rsa_sha1
    alg = _jwt_rs1_signing_algorithm()
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth1/rfc5849/signature.py", line 473, in _jwt_rs1_signing_algorithm
    import jwt.algorithms as jwtalgo
ImportError: No module named jwt.algorithms

I’ve tried this on Gentoo and Ubuntu, with the same results. On Gentoo, I then installed pyjwt with pip, and got this:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/xero/manager.py", line 177, in wrapper
    params=params, cert=cert, timeout=timeout)
  File "/usr/lib64/python2.7/site-packages/requests-2.7.0-py2.7.egg/requests/api.py", line 122, in put
    return request('put', url, data=data, **kwargs)
  File "/usr/lib64/python2.7/site-packages/requests-2.7.0-py2.7.egg/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/lib64/python2.7/site-packages/requests-2.7.0-py2.7.egg/requests/sessions.py", line 451, in request
    prep = self.prepare_request(req)
  File "/usr/lib64/python2.7/site-packages/requests-2.7.0-py2.7.egg/requests/sessions.py", line 382, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib64/python2.7/site-packages/requests-2.7.0-py2.7.egg/requests/models.py", line 308, in prepare
    self.prepare_auth(auth, url)
  File "/usr/lib64/python2.7/site-packages/requests-2.7.0-py2.7.egg/requests/models.py", line 496, in prepare_auth
    r = auth(self)
  File "/usr/lib64/python2.7/site-packages/requests_oauthlib-0.5.0-py2.7.egg/requests_oauthlib/oauth1_auth.py", line 79, in __call__
    unicode(r.url), unicode(r.method), r.body or '', r.headers)
  File "build/bdist.linux-x86_64/egg/oauthlib/oauth1/rfc5849/__init__.py", line 313, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "build/bdist.linux-x86_64/egg/oauthlib/oauth1/rfc5849/__init__.py", line 150, in get_oauth_signature
    sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
  File "build/bdist.linux-x86_64/egg/oauthlib/oauth1/rfc5849/signature.py", line 505, in sign_rsa_sha1_with_client
    return sign_rsa_sha1(base_string, client.rsa_key)
  File "build/bdist.linux-x86_64/egg/oauthlib/oauth1/rfc5849/signature.py", line 496, in sign_rsa_sha1
    alg = _jwt_rs1_signing_algorithm()
  File "build/bdist.linux-x86_64/egg/oauthlib/oauth1/rfc5849/signature.py", line 474, in _jwt_rs1_signing_algorithm
    _jwtrs1 = jwtalgo.RSAAlgorithm(jwtalgo.hashes.SHA1)
AttributeError: 'module' object has no attribute 'RSAAlgorithm'

Installing python-jwt on the Ubuntu machine made no difference.

PyCrypto is installed (2.6.1) on both machines. JWT appears to be required, pip doesn’t install it automatically as a dependency, but even when it is installed, the thing doesn’t seem to be able to load up the crypto libraries it wants. Am I taking crazy pills, or is something very wrong here?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
timrichardsoncommented, Jan 28, 2016

Installing pip install cryptography as per https://github.com/freakboy3742/pyxero/issues/90 fixed it for me (Python 3.5.1, latest release of all packages)

3reactions
innerteapotcommented, Mar 21, 2016

I just got this error using pyxero 0.7.0 with Python 2.7.6 on pythonanywhere.com. Downgrading to oauthlib 0.7.2 solved the issue for me.

pip install oauthlib==0.7.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyJWT won't import jwt.algorithms (ModuleNotFoundError
I had the same issue. The error seems to be a conflict between the pyjwt and jwt modules (as mentioned by @vimalloc above)....
Read more >
[Fixed] ModuleNotFoundError: No module named 'pyjwt' - Finxter
Quick Fix: Python raises the ImportError: No module named 'pyjwt' when it cannot find the library pyjwt . The most frequent source of...
Read more >
ImportError: No module named jwt.algorithms - Bountysource
After installing pyxero 0.7.0 via pip, and attempting to connect to a Private Application, I get the following ImportError:
Read more >
No module named 'jwt.exceptions'-django - appsloveworld
Coding example for the question from .exceptions import InvalidKeyError ModuleNotFoundError: No module named 'jwt.exceptions'-django.
Read more >
Python – import jwt ImportError: No module named jwt
Traceback (most recent call last): File "main.py", line 8, in <module> import jwt ImportError: No module named jwt. I worked with similar errors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found