with让数据库操作代码变得清爽
Python.h:没有那个文件或目录

SimpleHttpServer出现unicodeDecodeError

妙音 posted @ 2013年12月30日 09:46 in python , 2550 阅读

在win8系统下运行 python -m SimpleHTTPServer 出现Traceback (most recent call last):

  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后面加上下面语句

reload(sys)
sys.setdefaultencoding('gbk')
Avatar_small
farhan 说:
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

Avatar_small
farhan 说:
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
Avatar_small
farhan 说:
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


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter