Converting to UTF-8 (again)

前端 未结 3 1157
天涯浪人
天涯浪人 2021-01-20 07:25

I\'ve this string Traor\\u0102\\u0160

Traor\\u0102\\u0160 Should produce Traoré. Then Traoré utf-8 decoded shou

3条回答
  •  既然无缘
    2021-01-20 07:51

    You need tell requests what encoding to expect:

    >>> import requests
    >>> r = requests.get(url)
    >>> r.encoding = 'UTF-8'
    >>> r.json[u'Item'][u'LastName']
    u'Traor\xe9'
    

    Otherwise, you'll get this:

    >>> r = requests.get(url)
    >>> r.json['Item']['LastName']
    u'Traor\u0102\u0160'
    

提交回复
热议问题