I have built a Django management command that prints out some stuff on stdout (using print
). All works fine, but...
When I try to redirect the output to a file, using
./manage.py my_command > a_file.txt
I get:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 14: ordinal not in range(128)
No traceback, just that.
I tried ./manage.py my_command | less
just for the fun of it, and it showed some output, presumably lines before first non-ASCII char was encountered. Output has some UTF-8 chars, no way around that.
Same error happens on Mac laptop and on Red Hat Linux server. Using Python 2.7.9
What's happening here, and how can I dump the info to a file?