Skip to content

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

Open

Description

@supermitch

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

Activity

  1. sujaygarlanka commented on Jul 17, 2020

    @sujaygarlanka
    Contributor

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

  2. sujaygarlanka commented on Sep 10, 2020

    @sujaygarlanka
    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!

  3. federicojasson commented on Oct 14, 2021

    @federicojasson

    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.

  4. regoawt commented on Jul 3, 2023

    @regoawt

    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
    
  5. bvrs-atri commented on May 21, 2025

    @bvrs-atri

    Hi @regoawt, I'm facing the same issue when trying to use Boxsdk as a layer for Lambda Function.

    This is what i followed to create layer. AWS Docs

    I have tried installing only Boxsdk (without boxsdk[jwt]) and both of them at once as well. But i still see the issue

    [ERROR] AttributeError: 'NoneType' object has no attribute 'from_settings_dictionary'
    Traceback (most recent call last):
      File "/var/task/lambda_function.py", line 70, in lambda_handler
        auth = JWTAuth.from_settings_dictionary(json.loads(secret))
    

    Runtime : Python 3.11

    I've read in some articles that it's important where we build the package. So i've tried building it both it local pc and in the cloudshell as well. Yet the issue persists

    Anyway to solve this ?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions