Docker pip "EOFError: EOF when reading a line" with private pypi

  docker, gitlab, pip, python, python-poetry

Using docker, I’m trying to install requirements from private gitlab (domain name changed here ofc) pypi, on pip install I’m getting input, and EOFError:

FROM python:3.9

WORKDIR /server/
ARG GITLAB_ACCESS_TOKEN
COPY requirements.txt /server/
RUN pip install
 --index-url https://__token__:[email protected]/api/v4/projects/50/packages/pypi/simple
 --extra-index-url https://pypi.org/simple
 -r requirements.txt

COPY . /server/
CMD gunicorn example.wsgi:application --bind 0.0.0.0:8000 --reload

Step 5/7 : RUN pip install -r requirements.txt
 ---> Running in 91bfbea64ebf
Looking in indexes: https://pypi.org/simple, https://gitlab.example.com/api/v4/projects/50/packages/pypi/simple
User for gitlab.example.com: ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 171, in _merge_into_criterion
    crit = self.state.criteria[name]
KeyError: 'asgiref'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 189, in _main
    status = self.run(options, args)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 178, in wrapper
    return func(self, options, args)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 316, in run
    requirement_set = resolver.resolve(
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 121, in resolve
    self._result = resolver.resolve(
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 453, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 318, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _merge_into_criterion
    crit = Criterion.from_requirement(self._p, requirement, parent)
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 82, in from_requirement
    if not cands:
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/resolvelib/structs.py", line 124, in __bool__
    return bool(self._sequence)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in __bool__
    return any(self)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 35, in _iter_built
    for version, func in infos:
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 220, in iter_index_candidate_infos
    result = self._finder.find_best_candidate(
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/index/package_finder.py", line 872, in find_best_candidate
    candidates = self.find_all_candidates(project_name)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/index/package_finder.py", line 815, in find_all_candidates
    package_links = self.process_project_url(
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/index/package_finder.py", line 779, in process_project_url
    html_page = self._link_collector.fetch_page(project_url)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/index/collector.py", line 617, in fetch_page
    return _get_html_page(location, session=self.session)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/index/collector.py", line 429, in _get_html_page
    resp = _get_html_response(url, session=session)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/index/collector.py", line 126, in _get_html_response
    resp = session.get(
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/network/session.py", line 424, in request
    return super().request(method, url, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py", line 662, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pip/_vendor/requests/hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/network/auth.py", line 256, in handle_401
    username, password, save = self._prompt_for_password(parsed.netloc)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/network/auth.py", line 226, in _prompt_for_password
    username = ask_input(f"User for {netloc}: ")
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 237, in ask_input
    return input(message)
EOFError: EOF when reading a line
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 2
make: *** [Makefile:4: build] Error 2

Tried to add --no-input argument, but got this:

Step 5/7 : RUN pip install --index-url https://__token__:[email protected]/api/v4/projects/50/packages/pypi/simple --extra-index-url https://pypi.org/simple -r requirements.txt --no-input
 ---> Running in a4f8a70fa398
Looking in indexes: https://__token__:****@gitlab.example.com/api/v4/projects/50/packages/pypi/simple, https://pypi.org/simple, https://gitlab.example.com/api/v4/projects/50/packages/pypi/simple
Collecting asgiref==3.3.1
  Downloading asgiref-3.3.1-py3-none-any.whl (19 kB)
Collecting certifi==2020.12.5
  Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Collecting chardet==4.0.0
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
ERROR: Could not find a version that satisfies the requirement django-custom-package==0.1.1
ERROR: No matching distribution found for django-custom-package==0.1.1
The command '/bin/sh -c pip install --index-url https://__token__:[email protected]/api/v4/projects/50/packages/pypi/simple --extra-index-url https://pypi.org/simple -r requirements.txt --no-input' returned a non-zero code: 1
make: *** [Makefile:4: build] Error 1

Tried to hardcode token, but got the same.

ARG GITLAB_ACCESS_TOKEN=abcd

Before that I tried to manage installation with poetry
(poetry config http-basic.mypypi __token__ $GITLAB_ACCESS_TOKEN; poetry install, but got the same exception, also tried hardcode).

Idk what to do, native execution in bash works fine with both poetry and pip (python3.9 too ofc, latest pip).

Source: Docker Questions

LEAVE A COMMENT