變相解決 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 <module>
    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

這裏寫圖片描述

從圖中可以看出來問題從 encoding.py中出來的,於是我點開encoding.py,找到那一行
這裏寫圖片描述
不就是一個編碼不是utf-8報錯唄,但是我又找不到哪裏不是,於是我就掩耳盜鈴的把if註釋掉了,然後就不會報錯了,程序也完美運行了。
這裏寫圖片描述
這個故事告訴我們,有時候不要要求太高了,適當的知足一下你會過得反而更好。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章