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.