H
H
hubble2020-12-13 19:50:54
Python
hubble, 2020-12-13 19:50:54

Response is returned in Unicode. How to change encoding?

# -*- coding: utf-8 -*-
import requests

ajax_url = 'http://wordsteps.com/ajax/ajax_handler.php?'
headers_dict = {'Content-Type': 'text/plain; charset=UTF-8'}
payload = 'class=dicts/DictWords&template=dicts/DictWords.tpl&dictID=136958&pageNum=1&RsAjaxComponent=1&curURL=http%3A//wordsteps.com/vocabulary/words/136958/8000%2B%25D0%259E%25D1%2581%25D0%25BD%25D0%25BE%25D0%25B2%25D0%25BD%25D1%258B%25D1%2585%2B%25D0%25B0%25D0%25BD%25D0%25B3%25D0%25BB%25D0%25B8%25D0%25B9%25D1%2581%25D0%25BA%25D0%25B8%25D1%2585%2B%25D1%2581%25D0%25BB%25D0%25BE%25D0%25B2'


if __name__ == '__main__':
    r = requests.post(ajax_url, headers=headers_dict, data=payload)
    r.encoding
    print(r.encoding)
    print(r.text)


Response is returned with Unicode characters . Unable to recode.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-12-13
@hubbletvv

print(bytes(r.text, 'ascii').decode('unicode-escape'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question