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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM