ImportError: no module named cryptography.hazmat.backends - boxsdk on Mac

I'm currently trying to automate uploading a single file (for now) to Box from my Python automation.

I use the code from the Box developers website, which should be β€œsuper easy to use,” but I get an error (see above) when I try to run the simple program found on this page: https: // www. box.com/blog/introducing-box-python-sdk/ . I added the client identifier, client secret and developer token, and added the path to my zip file for download and continue to receive the above error. I have not changed anything beyond this.

Code for those who do not want to follow the link :)

from boxsdk import Client, OAuth2 oauth = OAuth2( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", access_token="YOUR_DEVELOPER_TOKEN", ) client = Client(oauth) shared_folder = client.folder( folder_id='0', ).create_subfolder('shared_folder') uploaded_file = shared_folder.upload('/path/to/file') shared_link = shared_folder.get_shared_link() 

I installed the cryptographic program using pip and easy_install to be sure, as well as libffi and openssl and oauth2 just to be safe and nothing works. Can anybody help me?

Thanks Gary

+6
source share
3 answers

This error has nothing to do with the boxsdk library, but with one of its dependencies: cryptography .

In most cases, this is due to an unsuccessful installation of the cryptography library. In most cases, this was unsuccessful because libffi is not installed by default on most computers.

If you are using brew, just go to your terminal and type brew install libffi

Then reinstall cryptography or boxsdk with pip :

pip install cryptography --force-reinstall

+8
source

Try it. Good luck

 rm -rf /usr/local/lib/python2.7/dist-packages/fabric/fabric-home-assistant sudo apt-get install libffi-dev libssl-dev sudo pip install cryptography --force-reinstall 
+4
source

I had exactly the same error when trying to run paramiko on AWS Lambda, which depends on pycrypto. I fixed it by following these steps before I installed for each of them:

 sudo yum install gcc libffi-devel python-devel openssl-devel 

This seemed to work because the pycrypto pip install looked for headers that could not be found.

+2
source

All Articles