Solution fo "LookupError: unknown encoding: A" when running Trac 1.2 on WIndows with Python 2.6.x

When installing & running standalone Trac 1.2.x on Windows, an error could happen after you firstly visit your Trac website:

LookupError: unknown encoding: A

It's probably caused by messy encoding issue of your Windows CMD environment.

There is a simple workaround to resolve this issue. Check the error message, and trace back to site-packages\trac\util\datefmt.py, function _format_datetime_without_babel(t, format)

You can see the final encoding is determined by 3 possible sources:

encoding = getlocale(LC_TIME)[1] or getpreferredencoding() or sys.getdefaultencoding()

If you try to import appropriate modules and print out these source, the results can help you understanding exact what encoding could be used.  In my case, the results are empty, "cp950", and "ascii" respectively.

Encoding "cp950" usually causes painful issues when executing Python code...

So, the workaround is to comment the original encoding retrieval statement, and use system default encoding  instead:

#encoding = getlocale(LC_TIME)[1] or getpreferredencoding() or sys.getdefaultencoding()
encoding = sys.getdefaultencoding()

Stop and restart tracd.exe, and it should get you the Trac project selection frontpage.


Designed by Posicionamiento Web | Modified by seLain | Bloggerized by GosuBlogger | Blue Business Blogger