box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
413 stars 214 forks source link

Update boxsdk to use requests-toolbelt >= 1.0.0. #869

Closed ikwyl6 closed 4 months ago

ikwyl6 commented 4 months ago

Now when I install $ pip install -U 'requests-toolbelt>=1' I get the following:

Description of the Issue

Currently boxsdk uses requests-toolbelt>=0.4.0. During an upgrade of requests-toolbelt to 1.0.0, they removed Google's Engine 'appengine' that was part of their pkg requests-toolbelt HISTORY and urllib3 also removed appengine from their package. When this happened it broke a few dependencies.

Steps to Reproduce

  1. Install a venv and install requests and boxsdk via pip: pip install requests boxsdk. Doing this installs urllib3 2.2.1 and requests 2.31.0, and requests-toolbelt 0.10.1.
  2. Once that happens and I use my script that uses boxsdk 2.10.0 I get the following error:

    $ python ./box_upload.py -h 
    Traceback (most recent call last):
    File "/dev/venv/lib/python3.11/site-packages/requests_toolbelt/_compat.py", line 48, in <module>
    from requests.packages.urllib3.contrib import appengine as gaecontrib
    ImportError: cannot import name 'appengine' from 'requests.packages.urllib3.contrib' (/dev/venv/lib/python3.11/site-packages/urllib3/contrib/__init__.py)
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    File "/dev/box_upload/./box_upload.py", line 10, in <module>
    from boxsdk import OAuth2, Client, BoxAPIException
    File "/dev/venv/lib/python3.11/site-packages/boxsdk/__init__.py", line 5, in <module>
    from .auth import JWTAuth, OAuth2
    File "/dev/venv/lib/python3.11/site-packages/boxsdk/auth/__init__.py", line 5, in <module>
    from .cooperatively_managed_oauth2 import CooperativelyManagedOAuth2
    File "/dev/venv/lib/python3.11/site-packages/boxsdk/auth/cooperatively_managed_oauth2.py", line 4, in <module>
    from .oauth2 import OAuth2
    File "/dev/venv/lib/python3.11/site-packages/boxsdk/auth/oauth2.py", line 20, in <module>
    from ..session.session import Session
    File "/dev/venv/lib/python3.11/site-packages/boxsdk/session/session.py", line 18, in <module>
    from ..util.multipart_stream import MultipartStream
    File "/dev/venv/lib/python3.11/site-packages/boxsdk/util/multipart_stream.py", line 7, in <module>
    from requests_toolbelt.multipart.encoder import MultipartEncoder
    File "/dev/venv/lib/python3.11/site-packages/requests_toolbelt/__init__.py", line 12, in <module>
    from .adapters import SSLAdapter, SourceAddressAdapter
    File "/dev/venv/lib/python3.11/site-packages/requests_toolbelt/adapters/__init__.py", line 12, in <module>
    from .ssl import SSLAdapter
    File "/dev/venv/lib/python3.11/site-packages/requests_toolbelt/adapters/ssl.py", line 16, in <module>
    from .._compat import poolmanager
    File "/dev/venv/lib/python3.11/site-packages/requests_toolbelt/_compat.py", line 50, in <module>
    from urllib3.contrib import appengine as gaecontrib
    ImportError: cannot import name 'appengine' from 'urllib3.contrib' (/dev/venv/lib/python3.11/site-packages/urllib3/contrib/__init__.py)
  3. Researching for answer, I found this where it says to upgrade to requests-toolbelt 1.0.0 as the support for google's appengine has been removed (not needed) and should fix this ImportError:
    $ pip install -U 'requests-toolbelt>=1'
    Collecting requests-toolbelt>=1
    Downloading requests_toolbelt-1.0.0-py2.py3-none-any.whl.metadata (14 kB)
    Installing collected packages: requests-toolbelt
    Attempting uninstall: requests-toolbelt
    Found existing installation: requests-toolbelt 0.10.1
    Uninstalling requests-toolbelt-0.10.1:
    Successfully uninstalled requests-toolbelt-0.10.1
    ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
    boxsdk 2.10.0 requires requests-toolbelt<1.0.0,>=0.4.0, but you have requests-toolbelt 1.0.0 which is incompatible.
    Successfully installed requests-toolbelt-1.0.0

    If this is as easy as doing a PR for line 59 then let me know.

Testing my script with requests-toolbelt 1.0.0 installed seems to be working OK (no errors or exceptions).

Expected Behavior

boxsdk to use requests-toolbelt >=1.0.0 without issues.

Error Message, Including Stack Trace

Screenshots

Versions Used

Python SDK: boxsdk 2.10.0 Python: 3.11.7

arjankowski commented 4 months ago

Hi @ikwyl6 , thanks for reporting the issue.

I'd like to point out that the version of boxsdk you're using, 2.10.0, is EOL. Since version 3.7.0 of boxsdk, the problem seems to no longer occur because we removed the restriction from requests-toolbelt>=0.4.0, <1.0.0 to requests-toolbelt>=0.4.0.

Could you please retry your attempt with the latest version of our SDK 3.9.2, and let us know if this resolves the issue?

ikwyl6 commented 4 months ago

Well that was embarrassing! Was using boxsdk from 3 years ago.. I did a pip install -U boxsdk and it updated to 3.9.2 and it seems to work find (with my script). thank you..