python - JSON containing Chinese failed to dump as expected, (\\xxx\\xxx\\xxx)?
漂亮男人
漂亮男人 2017-05-18 10:58:57
0
1
663

Using Python's requests library to imitate a custom web client, I encountered an exception problem after submitting content containing Chinese characters.

After checking the raw of the request with Fiddler, we can see that the submission content of the official client is:

... {"jsonstr":"{\"pageindex\":1,\"keyword\":\"张三\"}"}

The self-defined client submission content is:

... {"jsonstr": "{'pageindex': 1,'keyword': '\xe5\xbc\xa0\xe4\xb8\x89'"}

The script for customizing the client is probably:

# -*- coding: utf-8 -*- keyword ='张三' jsonstr ={ "pageindex":1,"keyword":keyword} data = {"jsonstr":str(jsonstr)} r = requests.post(url, data =json.dumps(data))

Try data =json.dumps(data, ensure_ascii=False) but the situation remains the same.
If the keyword is a number, everything is normal.
The platform used is win7.

漂亮男人
漂亮男人

reply all (1)
漂亮男人
# coding: utf-8 import json keyword = '张三' jsonstr ={ "pageindex":1,"keyword":keyword} data = {"jsonstr": json.dumps(jsonstr, ensure_ascii=False)} r = requests.post(url, json=data)
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!