我正在使用请求库与MailChimp进行API调用。不幸的是,请求似乎错误地格式化了我的数据。
这是我arr
的json.dumps()。
[{"body": "{\"email_address\": testing1@gmail.com, \"status\":\"subscribed\",\"merge_fields\": {\"FNAME\":first}}", "path": "lists/xxx/members", "method": "POST"}, {"body": "{\"email_address\": testing1@gmail.com, \"status\":\"subscribed\", \"merge_fields\": {\"FNAME\":first}}", "path": "lists/xxx/members", "method": "POST"}, {"body": "{\"email_address\": testing@gmail.com, \"status\":\"subscribed\", \"merge_fields\": {\"FNAME\":second}}", "path": "lists/xxx/members", "method": "POST"}, {"body": "{\"email_address\": testing@gmail.com, \"status\":\"subscribed\", \"merge_fields\": {\"FNAME\":second}}", "path": "lists/xxx/members", "method": "POST"}]
这是请求使用json=arr
提交的内容:
{"body": "{\\"email_address\\": testing1@gmail.com, \\"status\\":\\"subscribed\\", \\"merge_fields\\": {\\"FNAME\\":first}}", "path": "lists/xxx/members", "method": "POST"}, {"body": "{\\"email_address\\": testing1@gmail.com, \\"status\\":\\"subscribed\\", \\"merge_fields\\": {\\"FNAME\\":first}}", "path": "lists/xxx/members", "method": "POST"}, {"body": "{\\"email_address\\": testing@gmail.com, \\"status\\":\\"subscribed\\", \\"merge_fields\\": {\\"FNAME\\":second}}", "path": "lists/xxx/members", "method": "POST"}, {"body": "{\\"email_address\\": testing@gmail.com, \\"status\\":\\"subscribed\\", \\"merge_fields\\": {\\"FNAME\\":second}}", "path": "lists/xxx/members", "method": "POST"}]}'
我也尝试过使用data=json.dumps(arr)
,但会产生相同的格式。关于为什么格式化添加第二个\ s的任何想法?
编辑:
以下是该计划中的相关代码:http://pastebin.com/Q0zjHxHP