ImportError when building Docker image: cannot import name 'appengine' from 'urllib3.contrib'

124 views Asked by At

I'm encountering an issue while building a Docker image within my environment managed by Poetry. The error message I receive is:

  ImportError
  cannot import name 'appengine' from 'urllib3.contrib' (/usr/local/lib/python3.9/site-packages/urllib3/contrib/__init__.py)
  at /usr/local/lib/python3.9/site-packages/requests_toolbelt/_compat.py:50 in <module>
       46│ else:
       47│     try:
       48│         from requests.packages.urllib3.contrib import appengine as gaecontrib
       49│     except ImportError:
    →  50│         from urllib3.contrib import appengine as gaecontrib
       51│ 
       52│ if requests.__build__ < 0x021200:
       53│     PyOpenSSLContext = None
       54│ else:

I'm using Poetry for dependency management and the image is built on python 3.9. This is the setup of my image.

ENV PYTHON_ENV=python3.9
RUN eval "$($SPARK_HOME/work-dir/miniconda/bin/conda shell.bash hook)" && \
    conda create --name ${PYTHON_ENV} python=3.9.12 &&  \
    conda config --set ssl_verify false && \
    rm -rf .env && \
    python -m venv .env && \
    chmod ga+rw .env


RUN eval "$($SPARK_HOME/work-dir/miniconda/bin/conda shell.bash hook)" && \
conda activate ${PYTHON_ENV} && \
conda install conda-pack && \
source .env/bin/activate && \
pip3 install --upgrade pip && \
pip3 install venv-pack && \
  repository_name[spark]==${PACKAGE_VERSION}

This is snippet of my gitlab-ci file (step publish docker) before_script: - poetry config virtualenvs.in-project true - poetry update - poetry install --extras spark docker_build: stage: docker only: - web dependencies: - build_and_publish before_script: - export PACKAGE_VERSION=$(cat pyproject.toml | head -5 | grep version | awk -F" '{print $2}') - export CI_CUSTOM_FLAGS=" --build-arg PACKAGE_VERSION=${PACKAGE_VERSION}"

After researching, I added the following dependencies to my pyproject.toml file in an attempt to resolve the issue:

    urllib3 = {version = "1.26.15" }
requests-toolbelt = {version = "0.10.1" }

Issue is still there. This are my dependencies in pyproject.toml

[tool.poetry.dependencies]
python = "^3.9"
pydantic = "^1.9.0"
PyYAML = "^6.0"
pyspark = {version = "3.1.1", optional = true}
pyarrow = "^8.0.0"
pandas = "^1.4.2"
urllib3 = {version = "1.26.15" }
requests-toolbelt = {version = "0.10.1" }

Any advice?

0

There are 0 answers