原文地址:
http://bbs.csdn.net/topics/390654855?page=1#post-396875208
本人 windows 7 下安装 webpy 0.3x 版本的时候出现如下的错误提示:
>>python setup.py install
File "setup.py", line 6, in <module>
from web import __version__
File "C:\Python27\web.py-0.37\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
File "C:\Python27\web.py-0.37\web\wsgi.py", line 12, in <module>
import httpserver
File "C:\Python27\web.py-0.37\web\httpserver.py", line 4, 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 0xc4 in position 33: ordinal
not in range(128)
根据最后一个提示:
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 0xc4 in position 33: ordinal
not in range(128)
对文件 "c:\Python27\lib\mimetypes.py" 以默认编码 ascii 方式读取出错(位置0xc4)。
更换文件的编码方式为 'gbk',成功。
方法: 在 "c:\Python27\lib\mimetypes.py" 的 import ... 语句下面添加如下代码
1
2
3
4
5
|
# begin added by semon for 'UnicodeDecodeError'
if
sys.getdefaultencoding() !
=
'gbk'
:
reload
(sys)
sys.setdefaultencoding(
'gbk'
)
# end added by semon
|
保存,退出。
再次执行
>>python setup.py install
成功。
尝试过将编码改为'utf-8',也失败了。不知道为什么。难道mimetypes.py中有中文不成,但我看了一下确实没有。
这是一个bug:http://bugs.python.org/issue10490
patch地址:http://bugs.python.org/file19746/mimetypes-patch2-2.7.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
Index: release27
-
maint
/
Lib
/
mimetypes.py
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
-
-
-
release27
-
maint
/
Lib
/
mimetypes.py (revision
86639
)
+
+
+
release27
-
maint
/
Lib
/
mimetypes.py (working copy)
@@
-
245
,
12
+
245
,
7
@@
ctype
=
_winreg.EnumKey(mimedb, i)
except
EnvironmentError:
break
-
try
:
-
ctype
=
ctype.encode(default_encoding)
# omit in 3.x!
-
except
UnicodeEncodeError:
-
pass
-
else
:
-
yield
ctype
+
yield
ctype
i
+
=
1
default_encoding
=
sys.getdefaultencoding()
|