You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've encountered an issue where sys.stdout.encoding can sometimes be None. This leads to a TypeError when calling the console_to_str method, as the console_encoding variable is also None.
Some containerized environments may not properly set the LC_ALL, LANG, or PYTHONIOENCODING environment variables, leading to sys.stdout.encoding being None.
console_encoding = sys.stdout.encoding if sys.stdout.encoding else sys.getdefaultencoding()
However, I am unsure if this is the best approach. Would love to hear your thoughts on whether this is the right fix or if there's a better alternative.
Thanks!
The text was updated successfully, but these errors were encountered:
tcaiazzi
changed the title
Handling TypeError when sys.stdout.encoding is None
Handling TypeError when sys.stdout.encoding is None
Jan 30, 2025
Hello!
We've encountered an issue where
sys.stdout.encoding
can sometimes be None. This leads to aTypeError
when calling theconsole_to_str method
, as theconsole_encoding
variable is also None.Possible Cases Where
sys.stdout.encoding
isNone
There are multiple scenarios where sys.stdout.encoding can be None, including:
Running in a non-interactive environment
Redirecting stdout to a file or a pipe
Running in certain containerized environments
Windows with specific configurations
Using custom or overridden
sys.stdout
streamsContext
This issue arises in [Kathará](https://github.com/KatharaFramework/Kathara), a container-based network emulator. More details can be found in [Kathará Issue #333](KatharaFramework/Kathara#333).
Possible Fix
A potential solution is the approach used [here](https://github.com/tcaiazzi/libtmux/blob/1bf73396ca579488a1f266a16e553f3ca735011e/src/libtmux/_compat.py#L7), which provides a fallback encoding:
However, I am unsure if this is the best approach. Would love to hear your thoughts on whether this is the right fix or if there's a better alternative.
Thanks!
The text was updated successfully, but these errors were encountered: