SimpleHttpServer出现unicodeDecodeError
妙音
posted @ 2013年12月30日 09:46
in python
, 2663 阅读
在win8系统下运行 python -m SimpleHTTPServer 出现Traceback (most recent call last):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | File "D:\Python27\lib\runpy.py" , line 162 , in _run_module_as_main "__main__" , fname, loader, pkg_name) File "D:\Python27\lib\runpy.py" , line 72 , in _run_code exec code in run_globals File "D:\Python27\lib\SimpleHTTPServer.py" , line 27 , in <module> class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): File "D:\Python27\lib\SimpleHTTPServer.py" , line 208 , in SimpleHTTPRequestHand ler 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 ) |
在import SimpleHTTPServer时,同样出现上面的错误.
在import sys后面加上下面语句
1 2 | reload (sys) sys.setdefaultencoding( 'gbk' ) |
2020年12月16日 01:19
You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog. Speed City Codes 2021
2020年12月20日 00:26 Thank you very much for sharing such a useful article. Will definitely saved and revisit your site navigate to this website
2020年12月24日 00:15
It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. huawei p30
2025年3月24日 18:20
I am perpetually thought about this, appreciate it for putting up. 바카라사이트