Edgewall Software
Modify

Opened 18 years ago

Closed 17 years ago

#5151 closed defect (fixed)

Browser requests w/ non-ASCII path trigger an error in the Python logger

Reported by: Emmanuel Blot Owned by: Emmanuel Blot
Priority: low Milestone: 0.11
Component: general Version: devel
Severity: minor Keywords: logger
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

When a request to browse a directory that contains non-ASCII characters, the Python logger triggers an un-noticed error:

192.168.25.1 - - [15/Apr/2007 01:37:06] "GET /project1/browser/branches/teste%CC%81 HTTP/1.1" 200 -
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/logging/__init__.py", line 731, in emit
    msg = self.format(record)
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/logging/__init__.py", line 617, in format
    return fmt.format(record)
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/logging/__init__.py", line 408, in format
    s = self._fmt % record.__dict__
UnicodeEncodeError: 'ascii' codec can't encode characters in position 43-44: ordinal not in range(128)

The error can probably be triggered with any requests that contains non-ASCII characters in the path part of the URL.

  • A possible workaround is to convert the URL path string to UTF-8:
    • trunk/trac/web/api.py

       
      169169
      170170    def __repr__(self):
      171171        return '<%s "%s %s">' % (self.__class__.__name__, self.method,
      172                                  self.path_info)
       172                                 self.path_info.encode('utf-8'))
      173173
      174174    # Public API

This error occurs when logger output is stderr (the terminal being configured to handle UTF-8). I'm not sure about how it behaves with other output stream such as syslog or a file.

Attachments (0)

Change History (4)

comment:1 by Christian Boos, 18 years ago

Milestone: 0.11

comment:2 by Christian Boos, 18 years ago

Milestone: 0.11.10.11
Owner: changed from Jonas Borgström to Emmanuel Blot

Yeah, I'm still seeing this. Please commit your suggested fix.

comment:3 by Emmanuel Blot, 18 years ago

Status: newassigned

I can't reproduce it anymore - weird.

I'm using the following setup:

Trac 0.11dev-r5785
Python 2.5 [GCC 4.0.1 (Apple Computer, Inc. build 5341)]
setuptools 0.6c5
SQLite 3.3.5
pysqlite 2.3.2
Genshi 0.5dev-r657
Pygments 0.7.1
Subversion 1.4.3 (r23084)
jQuery 1.1.2

Can you double check? I don't mind committing the fix, but it seems that the log output is ok w/o it, such as in:

01:29:06 Trac[main] DEBUG: Dispatching <Request "GET u'/browser/TV.com/test/Re\u0301pertoire a\u0300 proble\u0300mes'">

comment:4 by Christian Boos, 17 years ago

Resolution: fixed
Status: assignedclosed

Well, it seems r5646 did the trick.

I'm pretty sure I've seen the error in one circumstance in a later version, but I can't remember the config I used and steps to reproduce, so I'm closing it for now.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Emmanuel Blot.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Emmanuel Blot to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.