8000 Unable to import aiomysql while running as uid without account · Issue #587 · aio-libs/aiomysql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to import aiomysql while running as uid without account #587
Closed
@Nothing4You

Description

@Nothing4You

Hi,

I'm trying to run a script inside a container.
I don't know the UID the container runs as at build time and I don't want to initialize the container as root, so I can't workaround by creating the user at runtime.
This means that at runtime the UID the script is running as does not have an entry in /etc/passwd.

This is however expected at least in the current master at the time of writing, not sure if there are other places where this is expected in the code:

DEFAULT_USER = getpass.getuser()

Currently when trying to import aiomysql the following exception is raised:

Traceback (most recent call last):
  File "demo.py", line 2, in <module>
    import aiomysql
  File "/usr/local/lib/python3.7/site-packages/aiomysql/__init__.py", line 32, in <module>
    from .connection import Connection, connect
  File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 45, in <module>
    DEFAULT_USER = getpass.getuser()
  File "/usr/local/lib/python3.7/getpass.py", line 169, in getuser
    return pwd.getpwuid(os.getuid())[0]
KeyError: 'getpwuid(): uid not found: 12345'

To reproduce:

Dockerfile

FROM python:3.7-slim-buster

RUN pip3 install aiomysql

COPY demo.py /app/

WORKDIR /app

ENTRYPOINT ["/usr/bin/env", "python3", "demo.py"]

demo.py

print("Hello World from container")
import aiomysql
  1. build container DOCKER_BUILDKIT=1 docker build -t test-py .
  2. run container as uid 12345 docker run --rm -it --user 12345 test-py
  3. see KeyError

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0