Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

I'm doing an import data from a CSV file, after entering 210 lines, it returns me this error. I'm doing this from Django shell (manage.py shell)

ERROR - failed to write data to stream: <open file '<stdout>', mode 'w' at 0x104c8f150>
like image 610
Fernando Valente Avatar asked Jan 23 '15 17:01

Fernando Valente


2 Answers

This is a problem with the IPython encoding that is not UTF-8. export PYTHONIOENCODING=UTF-8 will solve it.

like image 188
lechatpito Avatar answered Nov 20 '22 05:11

lechatpito


This did the trick.

# sys.setdefaultencoding() does not exist, here!
import sys
reload(sys)  # Reload does the trick!
sys.setdefaultencoding('UTF-8')
like image 28
Parag Tyagi Avatar answered Nov 20 '22 07:11

Parag Tyagi