Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with RSAAlgorithm when trying to use private or partner apps #90

Closed
MJMortimer opened this issue Aug 13, 2015 · 12 comments
Closed

Comments

@MJMortimer
Copy link
Contributor

Hey guys, I'm testing using pyxero with different application types and for both private and partner I'm seeing the following error and am wondering if you have seen it before or know why?

Traceback (most recent call last):
File "", line 1, in
File "xero\auth.py", line 350, in init
self.init_credentials(oauth_token, oauth_token_secret)
File "xero\auth.py", line 146, in init_credentials
response = requests.post(url=url, auth=oauth, cert=self.client_cert)
File "c:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\api.py", line 109, in post
return request('post', url, data=data, json=json, *kwargs)
File "c:\Python27\lib\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 "c:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\sessions.py", line 451, in request
prep = self.prepare_request(req)
File "c:\Python27\lib\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 "c:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\models.py", line 308, in prepare
self.prepare_auth(auth, url)
File "c:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\models.py", line 496, in prepare_auth
r = auth(self)
File "c:\Python27\lib\site-packages\requests_oauthlib-0.5.0-py2.7.egg\requests_oauthlib\oauth1_auth.py", line 87, in call
unicode(r.url), unicode(r.method), None, r.headers)
File "c:\Python27\lib\site-packages\oauthlib\oauth1\rfc5849__init
.py", line 313, in sign
('oauth_signature', self.get_oauth_signature(request)))
File "c:\Python27\lib\site-packages\oauthlib\oauth1\rfc5849__init
.py", line 150, in get_oauth_signature
sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
File "c:\Python27\lib\site-packages\oauthlib\oauth1\rfc5849\signature.py", line 505, in sign_rsa_sha1_with_client
return sign_rsa_sha1(base_string, client.rsa_key)
File "c:\Python27\lib\site-packages\oauthlib\oauth1\rfc5849\signature.py", line 496, in sign_rsa_sha1
alg = _jwt_rs1_signing_algorithm()
File "c:\Python27\lib\site-packages\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'

@MJMortimer
Copy link
Contributor Author

Simply did not have cryptography installed.
pip install cryptography did the trick

@martinwinter
Copy link

This is still an issue. Please update the requirements to include the cryptography package!

@romgar
Copy link
Collaborator

romgar commented May 9, 2017

What do you mean @martinwinter ? cryptography is already in the list of dependencies.

@martinwinter
Copy link

@romgar Thanks for your quick response. Hm, I just installed pyxero via pip and had to manually install cryptography to make it work, hence my comment. Perhaps the configuration on pip is old? (Sorry, I am an experienced programmer but am just starting to use Python.)

@martinwinter
Copy link

martinwinter commented May 9, 2017

Here is my terminal output for installing pyxero (I ended up using Python 3 but it happened there as well):

mw-rmbp:PyXero martinwinter$ pip install pyxero
Collecting pyxero
  Using cached pyxero-0.8.0-py2.py3-none-any.whl
Collecting requests>=1.1.0 (from pyxero)
  Using cached requests-2.13.0-py2.py3-none-any.whl
Collecting PyJWT==1.4.0 (from pyxero)
  Using cached PyJWT-1.4.0-py2.py3-none-any.whl
Collecting requests-oauthlib>=0.3.0 (from pyxero)
  Using cached requests_oauthlib-0.8.0-py2.py3-none-any.whl
Requirement already satisfied: six>=1.8.0 in /usr/local/lib/python2.7/site-packages (from pyxero)
Collecting python-dateutil>=2.1 (from pyxero)
  Using cached python_dateutil-2.6.0-py2.py3-none-any.whl
Collecting oauthlib>=0.6.2 (from requests-oauthlib>=0.3.0->pyxero)
  Using cached oauthlib-2.0.2.tar.gz
Building wheels for collected packages: oauthlib
  Running setup.py bdist_wheel for oauthlib ... done
  Stored in directory: /Users/martinwinter/Library/Caches/pip/wheels/84/98/7a/fba7268f61097bea6081cbe5480bc439b38975748ea7684fd5
Successfully built oauthlib
Installing collected packages: requests, PyJWT, oauthlib, requests-oauthlib, python-dateutil, pyxero
Successfully installed PyJWT-1.4.0 oauthlib-2.0.2 python-dateutil-2.6.0 pyxero-0.8.0 requests-2.13.0 requests-oauthlib-0.8.0

And here is the error when trying to access an API endpoint:

>>> xero
<xero.api.Xero object at 0x105e5e110>
>>> xero.contacts.all()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/xero/basemanager.py", line 185, in wrapper
    params=params, cert=cert, timeout=timeout)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 407, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 306, in prepare
    self.prepare_auth(auth, url)
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 543, in prepare_auth
    r = auth(self)
  File "/usr/local/lib/python2.7/site-packages/requests_oauthlib/oauth1_auth.py", line 88, in __call__
    unicode(r.url), unicode(r.method), None, r.headers)
  File "/usr/local/lib/python2.7/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 314, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "/usr/local/lib/python2.7/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 151, in get_oauth_signature
    sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
  File "/usr/local/lib/python2.7/site-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/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 496, in sign_rsa_sha1
    alg = _jwt_rs1_signing_algorithm()
  File "/usr/local/lib/python2.7/site-packages/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'

@martinwinter
Copy link

Just FYI, I installed both Python versions with Homebrew.

@timrichardson
Copy link
Contributor

timrichardson commented May 19, 2017

I also now run into "AttributeError: module 'jwt.algorithms' has no attribute 'RSAAlgorithm'"
cryptography is installed. Python 3.6.1 on Ubuntu 16.04.2

@romgar
Copy link
Collaborator

romgar commented May 19, 2017

Can you try to install pyxero from the master branch and see if you still get this issue?

@timrichardson
Copy link
Contributor

Will do, but the error went away after I installed jwt manually. I now have an invalid key error, which may be correct, I will look into that now.

@timrichardson
Copy link
Contributor

timrichardson commented May 19, 2017

I installed from github but the invalid key error is actually an import error somewhere else

  alg = _jwt_rs1_signing_algorithm()
  File "/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/signature.py", line 473, in _jwt_rs1_signing_algorithm
    import jwt.algorithms as jwtalgo
  File "/usr/local/lib/python3.6/dist-packages/jwt/algorithms.py", line 5, in <module>
    from .exceptions import InvalidKeyError
ImportError: cannot import name 'InvalidKeyError'

Process finished with exit code 1

@romarpatindol
Copy link

romarpatindol commented Apr 20, 2018

I changed the dependencies to:
pycrypto 2.6.1
cryptography 1.3.1
oauthlib 0.7.2

Luckily, it works now.

@chandrakala-adsk
Copy link

chandrakala-adsk commented Jun 1, 2021

With Mac it still has the same issue, I am able to resolve it by using docker. Below is the command to install the required libraries via docker

image

And here are the components added in requirements.txt file
PyJWT==2.1.0
cryptography==3.4.7
bs4==0.0.1
oauthlib==3.1.0
rsa==4.7.2

I am adding the installed libraries to the current directory.

Reference link:
https://aws.amazon.com/premiumsupport/knowledge-center/lambda-layer-simulated-docker/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants