Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I'm using the code from the Box developers website that is supposed to be "super easy to use" but I am getting an error (see title above) when I try to run the simple program found on this page: https://www.box.com/blog/introducing-box-python-sdk/ . I've added my client ID, client secret, and developer token, and added the path to my zip file to upload, and keep getting the above error. I havent changed anything beyond that.

Code for those who dont want to click into 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've installed the cryptography program using pip AND easy_install just to be sure, along with libffi and openssl and oauth2 just to be safe and nothing works. Can anyone help me?

Thanks, Gary

like image 429
Gary Behan Avatar asked Jul 22 '15 16:07

Gary Behan


1 Answers

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

Most of the time, it happens because the cryptography library install failed. Most of the time, it failed because libffi is not installed by default on most computers.

If you're using brew, just go in your terminal and type brew install libffi

Then reinstall cryptography or boxsdk with pip:

pip install cryptography --force-reinstall

like image 98
ohe Avatar answered Nov 02 '22 20:11

ohe