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 can happen when passing objects as msg on python2 #107
Comments
NexediGitlab
pushed a commit
to SlapOS/slapos.core
that referenced
this issue
Nov 7, 2021
As reported on https://gi thub.com/xolox/python-coloredlogs/issues/107 logging objects with a __str__ method returning non-ascii characters raises UnicodeDecodeError. We have vendored coloredlogs version 0.5 long time ago, so just apply the suggested fix here for now.
NexediGitlab
pushed a commit
to SlapOS/slapos.core
that referenced
this issue
Nov 8, 2021
As reported on xolox/python-coloredlogs#107 logging objects with a __str__ method returning non-ascii characters raises UnicodeDecodeError. We have vendored coloredlogs version 0.5 long time ago, so just apply the suggested fix here for now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all, this is a problem only affecting python2.7, so if you think it's no longer relevant, don't hesitate to close this issue.
I thought that you might still be interested in this, because this package still claim to support python 2 in setup.py's classifiers and this is a scenario which works fine with standard logging, but breaks when coloredlogs is used. On python3 this problem does not happen.
Logging common API, described at https://docs.python.org/2/library/logging.html#logging.debug is:
the most common usage is to pass a string as
msg
, but as we can see in https://docs.python.org/3/howto/logging.html#using-arbitrary-objects-as-messages it's also supported to pass arbitrary objects asmsg
and their__str__
method will be used to convert the objects to string.When using python logging module, this works fine, even when the string contain non ascii characters, for example:
correctly output:
but when coloredlogs is used, like with this example:
an
UnicodeDecodeError
is raised:This happened with
humanfriendly==10.0
,coerce_string
is defined as https://github.com/xolox/python-humanfriendly/blob/6758ac61f906cd8528682003070a57febe4ad3cf/humanfriendly/compat.py#L101-L108Maybe this can be addressed in humanfriendly, by making
coerce_string
trying harder to decode the string, maybe something like this, because most strings are UTF-8 anyway:The text was updated successfully, but these errors were encountered: