Python UnicodeDecodeError

出于对goagent的兴趣,看了python,后来又想了解一下gae,于是就按照gae python创建hello world应用程序,可是一开始就遇到这样一个问题:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)

google发现这是python 2.7的一个bug:

This is a bug in mimetypes, triggered by bad data in the registry. (рєфшю/AMR is not at all a valid MIME media type.)

解决方案如下:

Index: Lib/mimetypes.py
===================================================================
--- Lib/mimetypes.py    (revision 85786)
+++ Lib/mimetypes.py    (working copy)
@@ -27,6 +27,7 @@
 import sys
 import posixpath
 import urllib
+from itertools import count
 try:
     import _winreg
 except ImportError:
@@ -239,19 +240,11 @@
             return
 
         def enum_types(mimedb):
-            i = 0
-            while True:
+            for i in count():
                 try:
-                    ctype = _winreg.EnumKey(mimedb, i)
+                    yield _winreg.EnumKey(mimedb, i)
                 except EnvironmentError:
                     break
-                try:
-                    ctype = ctype.encode(default_encoding) # omit in 3.x!
-                except UnicodeEncodeError:
-                    pass
-                else:
-                    yield ctype
-                i += 1
 
         default_encoding = sys.getdefaultencoding()
         with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,

改过后,经测试,app正常运行。

 

cite:

http://s2.codeinspot.com/q/1402649

http://bugs.python.org/issue9291

http://bugs.python.org/file19332/9291a.patch

posted on 2013-11-16 21:37  云化雨  阅读(2198)  评论(3编辑  收藏  举报

导航