我以前使用web.py没事,今天运行时报错,
mimetypes.init() # try to read system mime.types
File "D:\ProgramFiles\python2.7\lib\mimetypes.py", line 358, in init
db.read_windows_registry()
File "D:\ProgramFiles\python2.7\lib\mimetypes.py", line 258, in read_windows_r
egistry
for subkeyname in enum_types(hkcr):
File "D:\ProgramFiles\python2.7\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal
not in range(128)
可以看到,应该与读取注册表有关,在网上搜到了解决办法。由于装了阿里旺旺导致的。以下是转载的:
通过研究发现,安装时会检查HKEY_CLASSES_ROOT的子键,而邪恶的旺旺每次启动时都会在HKEY_CLASSES_ROOT增加一个'.阿里旺旺接收的可疑文件'键值,这个键值是中文的,就会读取时导致如下错误
1
2
3
4
5
6
7
8
|
mimetypes.init() # try to read system mime.types
File "D:\Python27\lib\mimetypes.py" , line 358 , in init
db.read_windows_registry()
File "D:\Python27\lib\mimetypes.py" , line 258 , in read_windows_registry
for subkeyname in enum_types(hkcr):
File "D:\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 0xb0 in position 1 : ordinal not in range ( 128 )
|
解决办法,删掉就行了,如果每次删掉比较麻烦,用autoit来删除,代码如下
1
|
RegDelete( 'HKEY_CLASSES_ROOT\.阿里旺旺接收的可疑文件' )
|
编译好的exe也可以在附件中下载
20131226更新:
不只是阿里旺旺会导致出错,只要是注册了中文后缀名都有可能出错,另外每次改也不是一个事儿,推荐一个一劳永逸的方法
进入python安装目录下的Lib目录,打开mimetypes.py文件
# end
即
1
2
3
4
5
6
7
|
# begin if sys.getdefaultencoding() ! = 'gbk' :
reload (sys)
sys.setdefaultencoding( 'gbk' )
# end default_encoding = sys.getdefaultencoding()
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: |