如何将json转换为用Python编写的x-www-form-urlencoded?
我正在使用下面的代码进行转换,但是它与邮递员编码的值不同,因此我得到了一个错误。
import json
from urllib.parse import urlencode
j = json.dump('json code')
encoded = urlencode(json.loads(j),encode='utf-8')我在下面的帖子请求中出现了错误。
"error": {
"status": 500,
"message": "Unexpected token '",
"message_shortcode": "unexpected token '",
"datetime": "20180102131407",
"url": "http://127.0.0.1:3001/api/searches/0SH69023763",
"qs": "type=form&result_options=%7B%22fieldset%22%3A%5B%22count%22%5D%7D",
"type": "InternalServerError",
"group": "server"
}发布于 2018-01-02 09:06:15
很明显,您的服务器API所期望的数据不是以预期的格式传递的,这破坏了服务器端代码的执行。-。
如果它希望Content报头是‘x form-urlencoded’,那么在向API URL发出请求时也要确保传递它。
有了请求模块,即使不用urllib的urlencode,也可以更容易地实现代码。所以,您也可以看看这里:http://docs.python-requests.org/en/v0.10.7/user/quickstart/
https://stackoverflow.com/questions/48057655
复制相似问题