Skip to main content
Question

Authentication Using JWT in Python "Nonetype" issue

  • May 22, 2025
  • 8 replies
  • 17 views

Forum|alt.badge.img

I am fairly new at box dev and JWT, so I had box generate a keypair for me, but the cert.pem file 

is run as a nonetype object. Can someone help me with this error/ how to authenticate using JWT in Python

(I've already used the SDK's instructions)

 

Here is the error message:

Traceback (most recent call last):
File "/Users/zperis/PycharmProjects/AutoBox/ImportTest.py", line 11, in
rsa_private_key_file_sys_path='/Users/zperis/Documents/cert.pem',
TypeError: 'NoneType' object is not callable

 

Here is my Source Code: 

from boxsdk import JWTAuth

auth = JWTAuth(
client_id='*******',
client_secret='*********',
enterprise_id='*******',
jwt_key_id= '********',
rsa_private_key_file_sys_path='/Users/zperis/Documents/cert.pem',
#store_tokens=your_store_tokens_callback_method,
)

access_token = auth.authenticate_instance()

from boxsdk import Client

client = Client(auth)

  

8 replies

Forum|alt.badge.img

Hi zperis, this Github issue should help with the problem. The gist from the comment is, "JWTAuth is only defined if its dependencies are available (which you get with pip install boxsdk[jwt])".

 

I created a quick sample with your code and my own credentials / keys, duplicated the error, then ran pip install boxsdk[jwt] to install the dependency, and that fixed it for me.

 

Hope that helps,

Jon


Forum|alt.badge.img

I had already pip installed box[sdk]

Perhaps my pem file is wrong? 

How do you make a pem file from the json downloaded from a box generated private key? 

What is with all the newline characters?

 

I'm on MacOs Sierra 10.12.5 


Forum|alt.badge.img

I'm still digging through for a potential solution to directly answer your question. Right now it looks like the Python SDK doesn't have a direct import for the .json files produced through the app process.

 

I'll keep looking for a direct solution for that, but in the meantime, let me provide you with an alternative to get you over the hurdle by creating your own keys.

 

To generate a new public / private key set in a terminal window, just run the following two commands: 

 

openssl genrsa -out private.pem 2048   
openssl rsa -in private.pem -outform PEM -pubout -out public.pem 

Now you can go to the "Add and Manage Public Keys" section of your app (under "Configuration"), and click "Add a public key". Copy in the contents of public.pem in the box, then click "Verify and Save". You can then change jwt_key_id to the new public key ID, and point rsa_private_key_file_sys_path to where that key is located. 

 

That's the process I followed for my app, but I did have to pip install boxsdk[jwt] specifically to bypass the original error you were getting.

 

- Jon

 

 


Forum|alt.badge.img

I followed your instructions and now get a :

ValueError: Could not unserialize key data.

I am running Python 2.7.

 

 


Forum|alt.badge.img

I am having the same problem. Is it the new lines that are throwing off the cryptography function load_pem_data()?


Forum|alt.badge.img

If you still have the same issue and you are using python 2.7, make sure to install PyJWT package for python 2.x instead of JWT for 3.x, so, uninstall jwt if you already have it, and install pyjwt.

 

pip uninstall jwt

then 

pip install pyjwt

 


Forum|alt.badge.img

Yup.  I had to literally run

pip install boxsdk[jwt]

Then most requirements were already met since I'd installed boxsdk, but additional things were then installed.

After that, the error went away.


Forum|alt.badge.img

Still getting this..... ;(

Class 'JWTAuth' does not define '__getitem__', so the '[]' operator cannot be used on its instances

appAuth = config["boxAppSettings"]["appAuth"]
TypeError: 'JWTAuth' object is not subscriptable