Handle wrongly encoded character in Python unicode string

前端 未结 5 593
暗喜
暗喜 2020-12-06 10:01

I am dealing with unicode strings returned by the python-lastfm library.

I assume somewhere on the way, the library gets the encoding wrong and returns a unicode str

5条回答
  •  死守一世寂寞
    2020-12-06 10:25

    You have to convert your unicode string into a standard string using some encoding e.g. utf-8:

    some_unicode_string.encode('utf-8')
    

    Apart from that: this is a dupe of

    BeautifulSoup findall with class attribute- unicode encode error

    and at least ten other related questions on SO. Research first.

提交回复
热议问题