变相解决 UnicodeDecodeError: 'utf8' codec can't decode byte0xc8 in position 9: invalid continuation byt

我在python 2.7.13环境下装了django,第一次 python manage.py runserver时遇到了这个错误,试了很多方法都没有解决,比如 修改电脑名,当然如果装python3就可以避免这个错误了,但是有些原因导致只能用python,我的解决方案是,先找到报错的地方,然而注释掉,即使它不是我亲生的,一样狠心下手。

"D:\PyCharm\PyCharm 2017.2.2\bin\runnerw.exe" D:\Python2\python2.exe D:/Myprogram/python/testdjango/manage.py runserver 8000
Traceback (most recent call last):
  File "D:/python/testdjango/manage.py", line 22, in 
    execute_from_command_line(sys.argv)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\commands\runserver.py", line 62, in execute
    super(Command, self).execute(*args, **options)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\commands\runserver.py", line 101, in handle
    self.run(**options)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\core\management\commands\runserver.py", line 110, in run
    autoreload.main(self.inner_run, None, options)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\utils\autoreload.py", line 341, in main
    reloader(wrapped_main_func, args, kwargs)
  File "D:\software\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\utils\autoreload.py", line 312, in python_reloader
    exit_code = restart_with_reloader()
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\utils\autoreload.py", line 294, in restart_with_reloader
    str_value = force_bytes(new_environ[key], encoding=encoding)
  File "D:\Python2\lib\site-packages\django-1.11.4-py2.7.egg\django\utils\encoding.py", line 124, in force_bytes
    return s.decode('utf-8', errors).encode(encoding, errors)
  File "D:\Python2\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc8 in position 9: invalid continuation byte

变相解决 UnicodeDecodeError: 'utf8' codec can't decode byte0xc8 in position 9: invalid continuation byt_第1张图片

从图中可以看出来问题从 encoding.py中出来的,于是我点开encoding.py,找到那一行
变相解决 UnicodeDecodeError: 'utf8' codec can't decode byte0xc8 in position 9: invalid continuation byt_第2张图片
不就是一个编码不是utf-8报错呗,但是我又找不到哪里不是,于是我就掩耳盗铃的把if注释掉了,然后就不会报错了,程序也完美运行了。
变相解决 UnicodeDecodeError: 'utf8' codec can't decode byte0xc8 in position 9: invalid continuation byt_第3张图片
这个故事告诉我们,有时候不要要求太高了,适当的知足一下你会过得反而更好。

你可能感兴趣的:(python,codec,utf-8,python,django)