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

ImportError: cannot import name 'appengine' from 'requests.packages.urllib3.contrib' #3

Open
Versallius opened this issue Jan 22, 2024 · 3 comments

Comments

@Versallius
Copy link

Versallius commented Jan 22, 2024

set up environment mostly according to the tutorial:

conda create -n mocca python=3.9
conda activate mocca
pip install git+https://github.com/HaasCP/mocca@master
pip3 install -U datapane==0.14
pip install notebook

while going through the cyanation tutorial, I use this code:

# folders handling
import os
from glob import glob

# user interaction
from mocca.user_interaction.campaign import HplcDadCampaign
from mocca.user_interaction.user_objects import Gradient
from mocca.user_interaction.user_objects import Compound
from mocca.user_interaction.user_objects import InternalStandard
from mocca.user_interaction.user_objects import HplcInput
from mocca.user_interaction.settings import Settings

# reporting
from mocca.report.main import report

And I get this error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\requests_toolbelt\_compat.py:48
     47 try:
---> 48     from requests.packages.urllib3.contrib import appengine as gaecontrib
     49 except ImportError:

ImportError: cannot import name 'appengine' from 'requests.packages.urllib3.contrib' (C:\Users\CGong\AppData\Local\anaconda3\envs\mocca\lib\site-packages\urllib3\contrib\__init__.py)

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
Cell In[1], line 14
     11 from mocca.user_interaction.settings import Settings
     13 # reporting
---> 14 from mocca.report.main import report

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\mocca\report\main.py:8
      1 # -*- coding: utf-8 -*-
      2 """
      3 Created on Wed May 25 08:39:04 2022
      4 
      5 @author: HaasCP
      6 """
----> 8 from mocca.report.hplc_input import report_hplc_input
      9 from mocca.report.gradient import report_gradients
     10 from mocca.report.chromatograms import report_chroms

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\mocca\report\hplc_input.py:11
      9 import os
     10 import pandas as pd
---> 11 import datapane as dp
     14 def exps_to_df(exps):
     15     """
     16     Transfers relevant information of HplcInput objects in a pandas df.
     17     """

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\datapane\__init__.py:28
     25 from .common.utils import enable_logging, log, _setup_dp_logging
     27 # Public API re-exports
---> 28 from .client.api import (
     29     Attachment,
     30     Media,
     31     BigNumber,
     32     Code,
     33     DataTable,
     34     Divider,
     35     Embed,
     36     Empty,
     37     File,
     38     Group,
     39     FontChoice,
     40     Formula,
     41     HTML,
     42     Media,
     43     Text,
     44     Page,
     45     PageLayout,
     46     Params,
     47     Plot,
     48     Report,
     49     ReportFormatting,
     50     ReportWidth,
     51     Result,
     52     Run,
     53     Schedule,
     54     App,
     55     Select,
     56     SelectType,
     57     Table,
     58     Text,
     59     TextAlignment,
     60     Toggle,
     61     Environment,
     62     by_datapane,
     63     signup,
     64     login,
     65     logout,
     66     ping,
     67     hello_world,
     68     builtins,
     69 )
     70 from .client.config import init
     71 from .common.dp_types import DPMode, set_dp_mode, get_dp_mode

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\datapane\client\api\__init__.py:50
     46 # flake8: noqa F401
     47 # Internal API re-exports
     48 import warnings
---> 50 from .common import HTTPError, Resource
     51 from .dp_object import DPObjectRef
     52 from .report.blocks import (
     53     Attachment,
     54     BigNumber,
   (...)
     71     Toggle,
     72 )

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\datapane\client\api\common.py:27
     25 from packaging.version import Version
     26 from requests import HTTPError, Response  # noqa: F401
---> 27 from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
     29 from datapane import _TEST_ENV, __version__
     30 from datapane.client import config as c

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\requests_toolbelt\__init__.py:12
      1 # -*- coding: utf-8 -*-
      2 """
      3 requests-toolbelt
      4 =================
   (...)
      9 :license: Apache v2.0, see LICENSE for more details
     10 """
---> 12 from .adapters import SSLAdapter, SourceAddressAdapter
     13 from .auth.guess import GuessAuth
     14 from .multipart import (
     15     MultipartEncoder, MultipartEncoderMonitor, MultipartDecoder,
     16     ImproperBodyPartContentException, NonMultipartContentTypeException
     17     )

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\requests_toolbelt\adapters\__init__.py:12
      1 # -*- coding: utf-8 -*-
      2 """
      3 requests-toolbelt.adapters
      4 ==========================
   (...)
      9 :license: Apache v2.0, see LICENSE for more details
     10 """
---> 12 from .ssl import SSLAdapter
     13 from .source import SourceAddressAdapter
     15 __all__ = ['SSLAdapter', 'SourceAddressAdapter']

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\requests_toolbelt\adapters\ssl.py:16
     12 import requests
     14 from requests.adapters import HTTPAdapter
---> 16 from .._compat import poolmanager
     19 class SSLAdapter(HTTPAdapter):
     20     """
     21     A HTTPS Adapter for Python Requests that allows the choice of the SSL/TLS
     22     version negotiated by Requests. This can be used either to enforce the
   (...)
     43     properly when used with proxies.
     44     """

File ~\AppData\Local\anaconda3\envs\mocca\lib\site-packages\requests_toolbelt\_compat.py:50
     48         from requests.packages.urllib3.contrib import appengine as gaecontrib
     49     except ImportError:
---> 50         from urllib3.contrib import appengine as gaecontrib
     52 if requests.__build__ < 0x021200:
     53     PyOpenSSLContext = None

ImportError: cannot import name 'appengine' from 'urllib3.contrib' (C:\Users\CGong\AppData\Local\anaconda3\envs\mocca\lib\site-packages\urllib3\contrib\__init__.py)

I'm not sure where the dependencies broke, but I was unable to do pip install mocca because the requirements in the pip package still uses sklearn rather than scikit-learn, so I had to improvise. I am working on Windows.

Edit: To clarify, the HplcDadCampaign and other classes used for analysis works fine, it's just report that is the problem.

@escheraz
Copy link
Collaborator

It looks like importing datapane (which is the package used to generate the reports) is causing an ImportError when importing appengine. Could you try updating the requests / urllib3 packages? I used the same commands you had above and I was able to successfully import the package. I have requests version 2.25.1 and urllib3 1.26.5.

@Versallius
Copy link
Author

Versallius commented Jan 30, 2024

in the earlier post i had requests==2.31.0 and urllib3==2.1.0.
upgrading to requests==2.25.1 and urllib3==1.26.5 worked, thanks!

@HaasCP
Copy link
Owner

HaasCP commented Jan 30, 2024

Solution is described here:

https://stackoverflow.com/questions/76175487/sudden-importerror-cannot-import-name-appengine-from-requests-packages-urlli

Since this repo will be deprecated soon, we will not fix it properly but leave this issue open for reference.

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

No branches or pull requests

3 participants