Python 问题 OSError: raw write() returned invalid length 42 (should have been between 0 and 21)

在使用 Fabric3 编写自动化部署文件时,遇到SError: raw write() returned invalid length 42 (should have been between 0 and 21) 的 BUG. 错误信息如下:

(venv) E:\Python_code\django\blogprojecttwo>fab deploy
[www.rubic.win] Executing task 'deploy'
[www.rubic.win] run: cd /home/gaoyan/sites/blogprojecttwo && git pull
[www.rubic.win] out: Already up-to-date.
[www.rubic.win] out:

[www.rubic.win] run:
        cd /home/gaoyan/sites/blogprojecttwo &&
        ../venv/bin/pip3 install -r requirements.txt &&
        ../venv/bin/python3 manage.py collectstatic --noinput &&
        ../venv/bin/python3 manage.py migrate

[www.rubic.win] out: Requirement already satisfied: asn1crypto==0.24.0 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt
(line 1))
[www.rubic.win] out: Requirement already satisfied: bcrypt==3.1.4 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (line
 2))
[www.rubic.win] out: Requirement already satisfied: cffi==1.11.5 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (line
3))
[www.rubic.win] out: Requirement already satisfied: cryptography==2.2.2 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt
 (line 4))
[www.rubic.win] out: Requirement already satisfied: Django==1.10.6 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (lin
e 5))
[www.rubic.win] out: Requirement already satisfied: django-haystack==2.6.1 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.
txt (line 6))
[www.rubic.win] out: Requirement already satisfied: enum34==1.1.6 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (line
 7))
[www.rubic.win] out: Requirement already satisfied: Fabric3==1.14.post1 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt
 (line 8))
[www.rubic.win] out: Requirement already satisfied: idna==2.6 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (line 9))

[www.rubic.win] out: Requirement already satisfied: ipaddress==1.0.19 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (
line 10))
[www.rubic.win] out: Requirement already satisfied: jieba==0.39 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (line 1
1))
[www.rubic.win] out: Requirement already satisfied: Markdown==2.6.11 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (l
ine 12))
[www.rubic.win] out: Requirement already satisfied: paramiko==2.4.1 in /home/gaoyan/sites/venv/lib/python3.4/site-packages (from -r requirements.txt (li
ne 13))
[www.rubic.win] out: Traceback (most recent call last):
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\main.py", line 763, in main
    *args, **kwargs
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\tasks.py", line 387, in execute
    multiprocessing
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\tasks.py", line 277, in _execute
    return task.run(*args, **kwargs)
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\tasks.py", line 174, in run
    return self.wrapped(*args, **kwargs)
  File "E:\Python_code\django\blogprojecttwo\fabfile.py", line 28, in deploy
    """.format(source_folder))
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\network.py", line 692, in host_prompting_wrapper
    return func(*args, **kwargs)
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\operations.py", line 1095, in run
    shell_escape=shell_escape, capture_buffer_size=capture_buffer_size,
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\operations.py", line 938, in _run_command
    capture_buffer_size=capture_buffer_size)
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\operations.py", line 820, in _execute
    worker.raise_if_needed()
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\thread_handling.py", line 26, in raise_if_needed
    six.reraise(e[0], e[1], e[2])
  File "e:\python_code\django\blogproject\venv\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\thread_handling.py", line 13, in wrapper
    callable(*args, **kwargs)
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\io.py", line 31, in output_loop
    OutputLooper(*args, **kwargs).loop()
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\io.py", line 143, in loop
    self._flush(self.prefix)
  File "e:\python_code\django\blogproject\venv\lib\site-packages\fabric\io.py", line 57, in _flush
    self.stream.flush()
OSError: raw write() returned invalid length 42 (should have been between 0 and 21)
[www.rubic.win] out: Disconnecting from www.rubic.win... done.
百度一下,找到了两篇博客找打了解决办法:
https://www.cnblogs.com/yanjj/p/8275995.html
https://blog.csdn.net/sinat_31790817/article/details/79161997

具体办法是 pip 安装 win_unicode_console, pip install win_unicode_console
在代码文件中添加以下两行代码:

import win_unicode_console
win_unicode_console.enable()

你可能感兴趣的:(Python,Python报错)