Posted by:
努力记

努力记,通过记录,计划,让自己的努力可以触碰彩虹!

3,685

Python:UnicodeDecodeError (2.7)

  • 2013-11-21
  • 暂无评论

在win7*64安装Python2.7.6后,安装setuptools出错

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,

 



back up ↑

无觅相关文章插件,快速提升流量