How to handle PodmanClient.exec_run(tty=False) when it returns a binary string prefix?

29 views Asked by At

Depending on the tty value, the bytes object of "output" returned from the exec_run() API may return an odd binary prefix:

import podman 
pc = podman.PodmanClient()
c = pc.containers.get('553e25cc3a')

c.exec_run(['/usr/bin/gcc', '--version'], tty=True)
(0, b'gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4.3.0.1)\r\nCopyright (C) 2021 Free Software Foundation, Inc.\r\nThis is free software; see the source for copying conditions.  There is NO\r\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r\n\r\n')

c.exec_run(['/usr/bin/gcc', '--version'], tty=False)
(0, b'\x01\x00\x00\x00\x00\x00\x00\xfdgcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4.3.0.1)\nCopyright (C) 2021 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n')

This showed up for me in version 4.7.0 becuase the default argument value of exec_run() tty changed from True to False, but it appears that in earlier versions of the Python podman client, manually setting tty=False it is reproducible.

How does one handle this situation? The conventional Python string decoding mechanism into UTF-8 fails:

rv, output = c.exec_run(['/usr/bin/gcc', '--version'], tty=False)
output.decode('UTF-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfd in position 7: invalid start byte

Suggestions? Anyone know why it is there? ... and what is it for?

I can certainly do:

output = output[8:].decode('UTF-8')

but I'm curious what the prefix is trying to indicate. Some alternate string encoding?

0

There are 0 answers