Django错误OSError: raw write() returned invalid length 14 (should have been between 0 and 7)

Posted 阿强Wwlt

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django错误OSError: raw write() returned invalid length 14 (should have been between 0 and 7)相关的知识,希望对你有一定的参考价值。

错误环境

使用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)的主要内容,如果未能解决你的问题,请参考以下文章

django 错误之 OSError: mysql_config not found

win10上 安装python环境遭遇OSError: raw write()

Django OSError:[Errno 13] 权限被拒绝

OSError: [Errno 2] 在 Django 中使用 python 子进程时没有这样的文件或目录

OSError:[Errno 2]在Django中使用python子进程时没有这样的文件或目录

尝试“pip install mysqlclient”时出现“OSError:mysql_config not found” - Django