UnicodeEncodeError: 'ascii' codec can't encode character

前端 未结 12 824
予麋鹿
予麋鹿 2020-11-30 20:31

When uploading files with non-ASCII characters I get UnicodeEncodeError:

Exception Type: UnicodeEncodeError at /admin/studio/newsitem/add/
Exception Value: \         


        
12条回答
  •  执念已碎
    2020-11-30 21:05

    Another useful option that avoids rewriting code is to change the default encoding for python.

    If you're using virtualenv you can change (or create if doesn't exist) env/lib/python2.7/sitecustomize.py and add:

    import sys
    sys.setdefaultencoding('utf-8')
    

    or, if you are in a production system, you can do the same to /usr/lib/python2.7/sitecustomize.py

提交回复
热议问题