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

Logging: Unicode Error #57441

Closed
guettli mannequin opened this issue Oct 20, 2011 · 4 comments
Closed

Logging: Unicode Error #57441

guettli mannequin opened this issue Oct 20, 2011 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@guettli
Copy link
Mannequin

guettli mannequin commented Oct 20, 2011

BPO 13232
Nosy @vsajip, @vstinner, @ezio-melotti
Files
  • unicodedecodeerror-in-logging.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-10-24.22:26:40.149>
    created_at = <Date 2011-10-20.14:43:19.447>
    labels = ['type-bug', 'library']
    title = 'Logging: Unicode Error'
    updated_at = <Date 2011-10-24.22:26:40.148>
    user = 'https://bugs.python.org/guettli'

    bugs.python.org fields:

    activity = <Date 2011-10-24.22:26:40.148>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-10-24.22:26:40.149>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2011-10-20.14:43:19.447>
    creator = 'guettli'
    dependencies = []
    files = ['23486']
    hgrepos = []
    issue_num = 13232
    keywords = []
    message_count = 4.0
    messages = ['146018', '146019', '146066', '146332']
    nosy_count = 5.0
    nosy_names = ['vinay.sajip', 'guettli', 'vstinner', 'ezio.melotti', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13232'
    versions = ['Python 2.7']

    @guettli
    Copy link
    Mannequin Author

    guettli mannequin commented Oct 20, 2011

    In changeset fe6be0426e0d the format() method was changed. Unfortunately it does not catch all unicode decode errors.

    I think line 482 of logging/init.py should be modified:
    to this (add 'replace'):

    s = s + record.exc_text.decode(sys.getfilesystemencoding(), 'replace')

    http://hg.python.org/cpython/file/f35514dfadf8/Lib/logging/__init__.py#l482

    Here is the stacktrace we get:
    {{{
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/logging/__init__.py", line 838, in emit
        msg = self.format(record)
      File "/usr/lib64/python2.7/logging/__init__.py", line 715, in format
        return fmt.format(record)
      File "/home/modbau_esg_p/djangotools/utils/logutils.py", line 32, in format
        msg=logging.Formatter.format(self, record)
      File "/usr/lib64/python2.7/logging/__init__.py", line 482, in format
        s = s + record.exc_text.decode(sys.getfilesystemencoding())
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 662: ordinal not in range(128)
    Logged from file base.py, line 209
    }}}

    @guettli guettli mannequin added the stdlib Python modules in the Lib dir label Oct 20, 2011
    @vsajip
    Copy link
    Member

    vsajip commented Oct 20, 2011

    Can you tell me what the actual data was which failed to be decoded? Is there more than one encoding in effect (e.g. one for the filesystem, and another for the other data in the exception being logged)?

    @ezio-melotti ezio-melotti added the type-bug An unexpected behavior, bug, or error label Oct 20, 2011
    @guettli
    Copy link
    Mannequin Author

    guettli mannequin commented Oct 21, 2011

    I attached a testcase (unicodedecodeerror-in-logging.py). If the filesystemencoding is UTF-8 and the source code is encoded in latin1, then the logging fails. It happens because there is a German umlaut in the comment behind 1/0.

    I added 'replace' to the decode() in __init__.py and the it works. The German umlaut gets displayed as inverted question mark. But this is better than no logging message.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 24, 2011

    New changeset 4bb1dc4e2cec by Vinay Sajip in branch '2.7':
    Closes bpo-13232: Handle multiple encodings in exception logging.
    http://hg.python.org/cpython/rev/4bb1dc4e2cec

    @python-dev python-dev mannequin closed this as completed Oct 24, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants