Python - 错误 - 无法将数据写入流:<打开文件"<stdout>",模式'w' 0x104c8f150>



我正在从CSV文件导入数据,输入210行后,它返回此错误。我从 Django shell (manage.py shell 中执行此操作)

ERROR - failed to write data to stream: <open file '<stdout>', mode 'w' at 0x104c8f150>

这是非 UTF-8 的 IPython 编码的问题。 export PYTHONIOENCODING=UTF-8会解决它。

这成功了。

# sys.setdefaultencoding() does not exist, here!
import sys
reload(sys)  # Reload does the trick!
sys.setdefaultencoding('UTF-8')

最新更新