Python : UnicodeEncodeError: 'latin-1' codec can't encode character

>>> u = u'hello\u2013world'
# 方案一
>>> u.encode('latin-1', 'replace')    # replace it with a question mark
'hello?world'

# 方案二
>>> u.encode('latin-1', 'ignore')     # ignore it
'helloworld'  

或者自己替换

>>> u.replace(u'\u2013', '-').encode('latin-1')
'hello-world'  

如果需要输出utf-8

>>> u.encode('utf-8')
'hello\xe2\x80\x93world'  

来源:https://stackoverflow.com/questions/8290206/python-unicodeencodeerror-latin-1-codec-cant-encode-character