friendlessstar 发表于 2015-4-21 12:50:42

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
页: [1]
查看完整版本: Python UnicodeDecodeError