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

Report helpful error message for missing "jwt" dependency #526

Open
supermitch opened this issue Jul 16, 2020 · 4 comments
Open

Report helpful error message for missing "jwt" dependency #526

supermitch opened this issue Jul 16, 2020 · 4 comments

Comments

@supermitch
Copy link

supermitch commented Jul 16, 2020

Is your feature request related to a problem? Please describe.

As is known from closed issue (#387) if you don't pip install "boxsdk[jwt]", and use the JWT authorization, you get a somewhat confusing message:

  File "/Users/first.last/workspace/repo_name/box/../lib/box.py", line 70, in get_jwt_client
    auth = boxsdk.JWTAuth.from_settings_file(load_config(self.app_name))
AttributeError: 'NoneType' object has no attribute 'from_settings_file'

Describe the solution you'd like

Return an error message instead that at least suggests "Did you try pip install boxsdk[jwt]?" when JWTAuth isn't going to work.

Additional context

Using sdk version boxsdk 2.9.0

@sujaygarlanka
Copy link
Contributor

@supermitch Thank you for the feedback! We will take a look at this.

@sujaygarlanka
Copy link
Contributor

@supermitch We are currently prioritizing bugs over enhancements in all our SDKs, so it may take a while for us to get to some of these. If are interested in submitting PRs for the enhancements, we would love to take a look!

@federicojasson
Copy link

federicojasson commented Oct 14, 2021

I'm having a similar issue when using the library in AWS Lambda, even though I installed the JWT extra (I downloaded the ZIP from Lambda and run it locally to double check):

$ tree

...
├── boxsdk
│   ├── auth
│   │   ├── cooperatively_managed_oauth2.py
│   │   ├── developer_token_auth.py
│   │   ├── __init__.py
│   │   ├── jwt_auth.py
...

My suspicion is that there's actually a different ImportError being raised, but it's not getting logged anywhere:

$ cat boxsdk/auth/__init__.py

# coding: utf-8

from __future__ import unicode_literals

from .cooperatively_managed_oauth2 import CooperativelyManagedOAuth2
from .developer_token_auth import DeveloperTokenAuth
try:
    from .jwt_auth import JWTAuth
except ImportError:
    JWTAuth = None  # If extras[jwt] are not installed, JWTAuth won't be available.

Update: I was able to log the error and my suspicion was confirmed:

Traceback (most recent call last):
--
File "/var/task/boxsdk/auth/__init__.py", line 8, in <module>
from .jwt_auth import JWTAuth
File "/var/task/boxsdk/auth/jwt_auth.py", line 12, in <module>
from cryptography.hazmat.primitives import serialization
File "/var/task/cryptography/hazmat/primitives/serialization/__init__.py", line 15, in <module>
from cryptography.hazmat.primitives.serialization.base import (
File "/var/task/cryptography/hazmat/primitives/serialization/base.py", line 11, in <module>
from cryptography.hazmat.primitives.asymmetric.types import (
File "/var/task/cryptography/hazmat/primitives/asymmetric/types.py", line 7, in <module>
from cryptography.hazmat.primitives.asymmetric import (
File "/var/task/cryptography/hazmat/primitives/asymmetric/dsa.py", line 12, in <module>
from cryptography.hazmat.primitives.asymmetric import (
File "/var/task/cryptography/hazmat/primitives/asymmetric/utils.py", line 6, in <module>
from cryptography.hazmat.bindings._rust import asn1
ImportError: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /var/task/cryptography/hazmat/bindings/_rust.abi3.so)

Would be nice to log these errors instead of swallowing them:

import logging

...
try:
    from .jwt_auth import JWTAuth
except ImportError:
    logging.exception("An import error occurred") # Could be a warning as well
    JWTAuth = None  # If extras[jwt] are not installed, JWTAuth won't be available.
...

It could also capture the error and ignore it if the cause is that the JWTAuth class is actually not found, while raising the error otherwise. I'm not entirely sure if it would raise an error unnecessarily in scenarios in which the user doesn't care about one of the extra modules.

@regoawt
Copy link

regoawt commented Jul 3, 2023

I've just been hit with the same issue as @federicojasson - issue with cryptography bindings when deployed on AWS Lambda being swallowed and raised as AttributeError: 'NoneType' object has no attribute 'from_settings_dictionary'.

Interestingly, the original error does get surfaced correctly when I import directly:

from boxsdk.auth.jwtauth import JWTAuth

rather than

from boxsdk import JWTAuth

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

No branches or pull requests

5 participants