datapane / datapane

Build and share data reports in 100% Python

Home Page:https://datapane.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: ImportError: cannot import name 'appengine' from 'urllib3.contrib'

i-magnus-k opened this issue · comments

Is there an existing issue for this?

  • I have searched for similar issues and discussions

Bug Description

I used an installation of DataPane a few weeks ago. I then created a new virtual env today and installed datapane via pip. Upon starting my app (which was working on the older venv), I get this error:

Traceback (most recent call last):
  File "C:\MyProject\venv\lib\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' (C:\MyProject\venv\lib\site-packages\urllib3\contrib\__init__.py)

Unfortunately I didn't look at the version of datapane used a few weeks ago, but can say that I installed datapane in the then venv on 1st of May.

I have googled the error and it possibly points to urllib3 v2.0.2
As an experiment, I upgraded requests_toolbelt to v1.0.0 and the issue was resolved

### System Information

```markdown
- Datapane version: 0.16.4
- Python version: 3.10.9
- Operating System: Windows 11
- Using Jupyter: No
- Pip or Conda: Pip
- Dependencies: From pip freeze
altair==4.2.2
asttokens==2.2.1
attrs==23.1.0
backcall==0.2.0
backoff==2.2.1
beautifulsoup4==4.12.2
bleach==6.0.0
boltons==21.0.0
certifi==2023.5.7
chardet==5.1.0
charset-normalizer==3.1.0
cheroot==9.0.0
click==8.1.3
click-spinner==0.1.10
colorama==0.4.6
colorlog==6.7.0
comm==0.1.3
dacite==1.8.0
datacommons==1.4.3
datacommons-pandas==0.0.3
datapane==0.16.4
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
dominate==2.7.0
dulwich==0.21.5
entrypoints==0.4
executing==1.2.0
face==20.1.1
fastjsonschema==2.16.3
furl==2.1.3
glom==23.3.0
idna==3.4
importlib-resources==5.12.0
ipykernel==6.23.0
ipynbname==2021.3.2
ipython==8.13.2
jaraco.functools==3.6.0
jedi==0.18.2
Jinja2==3.1.2
jsonschema==4.17.3
jupyter_client==8.2.0
jupyter_core==5.3.0
jupyterlab-pygments==0.2.2
lxml==4.9.2
MarkupSafe==2.1.2
matplotlib-inline==0.1.6
micawber==0.5.4
mistune==2.0.5
monotonic==1.6
more-itertools==9.1.0
multimethod==1.9.1
nbclient==0.7.4
nbconvert==7.4.0
nbformat==5.8.0
nest-asyncio==1.5.6
numpy==1.24.3
orderedmultidict==1.0.1
packaging==23.1
pandas==1.5.3
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
platformdirs==3.5.0
plotly==5.14.1
posthog==2.5.0
prompt-toolkit==3.0.38
psutil==5.9.5
pure-eval==0.2.2
pyarrow==10.0.1
pydantic==1.10.7
Pygments==2.15.1
pyngrok==5.2.3
pyrsistent==0.19.3
requests==2.30.0
requests-toolbelt==0.10.1
six==1.16.0
soupsieve==2.4.1
stack-data==0.6.2
tabulate==0.9.0
tenacity==8.2.2
tinycss2==1.2.1
toolz==0.12.0
tornado==6.3.1
traitlets==5.9.0
typing_extensions==4.5.0
urllib3==2.0.2
vega-datasets==0.9.0
wcwidth==0.2.6
webencodings==0.5.1

Anything else?

Full stack trace

Traceback (most recent call last):
  File "C:\MyProject\experimental\dashboard2.py", line 2, in <module>
    import datapane as dp
  File "C:\MyProject\venv\lib\site-packages\datapane\__init__.py", line 32, in <module>
    from .app.server import serve_app
  File "C:\MyProject\venv\lib\site-packages\datapane\app\server.py", line 31, in <module>
    from datapane.processors.processors import ExportBaseHTMLOnly
  File "C:\MyProject\venv\lib\site-packages\datapane\processors\__init__.py", line 2, in <module>
    from .api import build_report, save_report, stringify_report, upload_report
  File "C:\MyProject\venv\lib\site-packages\datapane\processors\api.py", line 19, in <module>
    from datapane.cloud_api.report import CloudReport
  File "C:\MyProject\venv\lib\site-packages\datapane\cloud_api\__init__.py", line 5, in <module>
    from .common import Resource
  File "C:\MyProject\venv\lib\site-packages\datapane\cloud_api\common.py", line 26, in <module>
    from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
  File "C:\MyProject\venv\lib\site-packages\requests_toolbelt\__init__.py", line 12, in <module>
    from .adapters import SSLAdapter, SourceAddressAdapter
  File "C:\MyProject\venv\lib\site-packages\requests_toolbelt\adapters\__init__.py", line 12, in <module>
    from .ssl import SSLAdapter
  File "C:\MyProject\venv\lib\site-packages\requests_toolbelt\adapters\ssl.py", line 16, in <module>
    from .._compat import poolmanager
  File "C:\MyProject\venv\lib\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' (C:\MyProject\venv\lib\site-packages\urllib3\contrib\__init__.py)
commented

Hi,
I was facing the same issue. It seems that from version 2.0 urllib3.contrib has no appengine. Fixing urllib3` to version 1.26.15 solved the issue for me.

Confirming the workaround is to upgrade requests-toolbelt>=1. Thanks for the suggestion!
There shouldn't be any breakages.

pip install -U 'requests-toolbelt>=1'
commented

Unfortunately, this workaround fails when managing dependencies with poetry, as datapane depends on requests_toolbelt<0.11.0:

poetry add requests_toolbelt>=1.0.0

Because datapane (0.16.4) depends on requests-toolbelt (>=0.9.1,<0.11.0)
 and no versions of datapane match >0.16.4,<0.17.0, datapane (>=0.16.4,<0.17.0) requires requests-toolbelt (>=0.9.1,<0.11.0).
So, because camtrail depends on both datapane (^0.16.4) and requests-toolbelt (1.0.0), version solving failed.

This could be solved by changing the dependencies in pyproject.toml accordingly.

we've released 0.16.5, which raises the constraint of requests-toolbelt.
This is the only change from 0.16.4

@antdking I found some other fixes on line (remove urllib3[appengine] or install 'appengine' separately) but they didn't work for me but your pip install -U 'requests-toolbelt>=1' worked for me. Thank you! I do have a dependency for requests-toolbelt < 1.0.0. Do you know if < 1.0.0. will work with this appengine fix?