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

UnicodeDecodeError getting container output #606

Closed
LewisGaul opened this issue Jul 8, 2024 · 0 comments · Fixed by #607
Closed

UnicodeDecodeError getting container output #606

LewisGaul opened this issue Jul 8, 2024 · 0 comments · Fixed by #607

Comments

@LewisGaul
Copy link
Collaborator

LewisGaul commented Jul 8, 2024

This is seen when calling DockerClient.container.run() or DockerClient.container.logs() if the container console contains output that is not UTF-8 encoded. This can be reproduced by outputting a character in another encoding as shown below.

Related to #370. Perhaps DockerClient.container.logs() should take an encoding parameter rather than assuming utf-8.

>>> import python_on_whales as pow
>>> podman = pow.DockerClient(client_call=["podman"])
>>> bash_cmd = r"echo -n $'\xfe'"
>>> full_cmd = ["bash", "-c", bash_cmd]
>>> ctr = podman.run("ubuntu", full_cmd)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python_on_whales/components/container/cli_wrapper.py", line 1764, in run
    return run(full_cmd, tty=tty, capture_stderr=False, pass_fds=pass_fds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python_on_whales/utils.py", line 215, in run
    return post_process_stream(completed_process.stdout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python_on_whales/utils.py", line 221, in post_process_stream
    stream = stream.decode()
             ^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte
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

Successfully merging a pull request may close this issue.

1 participant