UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 3 2: ordinal not in range(128)

后端 未结 6 1305
轻奢々
轻奢々 2020-11-30 22:50

I am parsing an xsl file using xlrd. Most of the things are working fine. I have a dictionary where keys are strings and values are lists of strings. All the keys and values

6条回答
  •  無奈伤痛
    2020-11-30 23:19

    As here str(u'\u2013') is causing error so use isinstance(foo,basestring) to check for unicode/string, if not of type base string convert it into Unicode and then apply encode

    if isinstance(foo,basestring):
        foo.encode('utf8')
    else:
        unicode(foo).encode('utf8')
    

    further read

提交回复
热议问题