1. 程式人生 > >【Django錯誤】OSError: raw write() returned invalid length 14 (should have been between 0 and 7)

【Django錯誤】OSError: raw write() returned invalid length 14 (should have been between 0 and 7)

安裝 opera 系統 package put handle out app brush

錯誤環境

使用Django框架創建完models類的之後,用python manage.py migrate命令來生成數據庫表的時候出錯

錯誤代碼

Operations to perform:
  Apply all migrations: SMS, admin, auth, contenttypes, sessions
Running migrations:
Running migrations:
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File 
"C:\python35\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line utility.execute() File "C:\python35\lib\site-packages\django\core\management\__init__.py", line 356, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\python35\lib\site-packages\django\core\management\base.py
", line 283, in run_from_argv self.execute(*args, **cmd_options) self.execute(*args, **cmd_options) File "C:\python35\lib\site-packages\django\core\management\base.py", line 330, in execute output = self.handle(*args, **options) File "C:\python35\lib\site-packages\django\core\management\commands\migrate.py
", line 177, in handle self.stdout.write(self.style.MIGRATE_HEADING("Running migrations:")) File "C:\python35\lib\site-packages\django\core\management\base.py", line 110, in write self._out.write(force_str(style_func(msg))) OSError: raw write() returned invalid length 42 (should have been between 0 and 21)

錯誤原因

與win10系統、版本有關系

可能是unicode字符的返回值問題

解決辦法

可以使用pip install win_unicode_console安裝win_unicode_console,在代碼文件中添加以下兩行代碼解決:

import win_unicode_console
win_unicode_console.enable()

  

【Django錯誤】OSError: raw write() returned invalid length 14 (should have been between 0 and 7)