2014-09-23 35 views
0

EDIT:问题通过贯通孔C解决:\ Python27 \ LIB \ mimetypes.py和添加代码缺点try块:Mimetypes.init()错误时

## Begin to line 245 :  
try: 
    ctype = _winreg.EnumKey(mimedb, i) 
except EnvironmentError: 
    break 
try: 
    ctype = ctype.encode(default_encoding) # omit in 3.x! 
except UnicodeEncodeError: 
    pass 

## Here, add the universal Exception missing. 
except Exception: 
    pass 

else: 
    yield ctype 

我从3天前开始搜索,但解决这个问题对我来说太难了。我不明白问题在哪里。

我试图通过使用GitHub,PowerShell 3等来安装我的软件包。所有这些都不起作用。除了PIP至极似乎有一个小错误...

当我试图通过使用PIP安装tweepy,这个错误追加:

Microsoft Windows [version 6.2.9200] 
(c) 2012 Microsoft Corporation. Tous droits réservés. 

C:\Users\user>pip install tweepy 
Downloading/unpacking tweepy 
    Downloading tweepy-2.3.0.tar.gz 
Cleaning up... 
Exception: 
Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main 
    status = self.run(options, args) 
    File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run 

    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl 
e=self.bundle) 
    File "C:\Python27\lib\site-packages\pip\req.py", line 1229, in prepare_files 
    req_to_install.run_egg_info() 
    File "C:\Python27\lib\site-packages\pip\req.py", line 292, in run_egg_info 
    logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.s 
etup_py, self.name)) 
    File "C:\Python27\lib\site-packages\pip\req.py", line 265, in setup_py 
    import setuptools 
    File "C:\Python27\lib\site-packages\setuptools\__init__.py", line 12, in <modu 
le> 
    from setuptools.extension import Extension 
    File "C:\Python27\lib\site-packages\setuptools\extension.py", line 7, in <modu 
le> 
    from setuptools.dist import _get_unpatched 
    File "C:\Python27\lib\site-packages\setuptools\dist.py", line 16, in <module> 
    from setuptools.depends import Require 
    File "C:\Python27\lib\site-packages\setuptools\depends.py", line 6, in <module 
> 
    from setuptools import compat 
    File "C:\Python27\lib\site-packages\setuptools\compat.py", line 19, in <module 
> 
    from SimpleHTTPServer import SimpleHTTPRequestHandler 
    File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in <module> 
    class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 
    File "C:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHand 
ler 
    mimetypes.init() # try to read system mime.types 
    File "C:\Python27\lib\mimetypes.py", line 358, in init 
    db.read_windows_registry() 
    File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry 
    for subkeyname in enum_types(hkcr): 
    File "C:\Python27\lib\mimetypes.py", line 249, in enum_types 
    ctype = ctype.encode(default_encoding) # omit in 3.x! 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 3: ordinal 
not in range(128) 

Storing debug log for failure in C:\Users\user\pip\pip.log 

你能解释一下我请,如何repear这个?

在此先感谢, SkyzohKey。

+0

什么是'点子--version'打印出来,又是什么'C:\用户\用户\ PIP \ pip.log'说? – thebjorn 2014-09-23 19:35:05

+0

'pip --version'什么也没说,程序没有找到。并且日志文件在这里:http://textup.fr/105784KS – SkyzohKey 2014-09-23 20:22:48

+0

当你调用它来安装('C:\ Users \ user> pip install tweepy')时,'pip --version'不能执行任何操作。 – thebjorn 2014-09-24 19:16:22

回答

0

看起来你有一个在注册表中导致问题的mimetype。您可以运行下面的脚本要弄清楚它是哪一个:

import _winreg 


def find_funky_mimetype(): 
    default_encoding = sys.getdefaultencoding() 
    with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, 
         r'MIME\Database\Content Type') as mimedb: 
     i = 0 
     while 1: 
      try: 
       ctype = _winreg.EnumKey(mimedb, i) 
      except EnvironmentError: 
       break 
      print 'testing:', `ctype`, 
      try: 
       ctype = ctype.encode(default_encoding) # omit in 3.x! 
      except UnicodeEncodeError: 
       print 'expected failure' 
      except Exception as e: 
       print 'unexpected failure:', e 
      else: 
       print 'ok.' 
      i += 1 


if __name__ == "__main__": 
    find_funky_mimetype() 

你应该做些什么完全取决于你,你感到舒服(例如移除从注册表有问题的MIME类型或添加除了`c:\ Python27 \ lib \ mimetypes.py'的第252行外,其他都是通用的,类似于我上面所做的)。

+0

我在运行脚本时没有任何错误,所有mimetypes都是“ok”。 (ps:你忘记导入sys ^^) – SkyzohKey 2014-09-25 16:47:05

+0

问题解决了!非常感谢Exception x) – SkyzohKey 2014-09-25 16:52:58

0

变线250

except (UnicodeEncodeError, UnicodeDecodeError): 
    pass 
+0

我已经解决了这个问题。 :X – SkyzohKey 2014-10-21 15:04:29