Python如何正确编码查询字符串参数,该参数是hmac sig的字典列表

时间:2019-03-25 00:28:41

标签: python arrays encoding parameters hmac

如何为包含字典列表的hmac哈希正确编码查询字符串参数。通过发布请求发送签名时,仅对整个参数dict进行简单编码是行不通的。转义字符越少越好。

import urllib

# this is the 'take_profit_step_orders' inside the dict i'm encoding

example = {"take_profit_step_orders": [{ "percent": 50, "price": 130, "price_method": "bid" }, {"percent": 50, "price": 140, "price_method": "bid" }]}

print(urllib.parse.urlencode(example))

#take_profit_step_orders=%5B%7B%27percent%27%3A+50%2C+%27price%27%3A+130%2C+%27price_method%27%3A+%27bid%27%7D%2C+%7B%27percent%27%3A+50%2C+%27price%27%3A+140%2C+%27price_method%27%3A+%27bid%27%7D%5D

0 个答案:

没有答案