【发布时间】:2020-05-08 22:34:09
【问题描述】:
我需要通过 python 脚本和 GET 数据连接 mailchimp API,我稍后会转移到 PowerBI for BI 解决方案。
我已阅读文档: https://mailchimp.com/developer/guides/get-started-with-mailchimp-api-3/#Parameters
我正在尝试获取特定报告 https://mailchimp.com/developer/reference/reports/#get_/reports/-campaign_id-
首先我设法使用以下代码连接到报告 (https://mailchimp.com/developer/reference/reports/#get_/reports/):
import requests
import json
r=requests.get("https://us11.api.mailchimp.com/3.0/reports/",
headers={"content-type": "application/json"},
auth=('anystring', 'myapikey')
,params={'fields':['id']})
data=r.json()
print(data)
r_dict = json.loads(r.text)
print(r.status_code)
print(r.text)
for i in r_dict:
print("key:", i,"val",r_dict[i])
然后我得到某种输出,这不是错误,而且似乎我已连接,因为我检索了数据。现在我正在尝试连接到特定的报告,我设置了一个 ID,但似乎我无法理解如何正确设置参数。我的代码如下所示:
r=requests.get("https://us11.api.mailchimp.com/3.0/reports/{80419197aa}",
headers={"content-type": "application/json"},
auth=('anystring', 'myapikey')
,params={'fields':['id','campaign_title','type','list_id']})
data=r.json()
print(data)
r_dict = json.loads(r.text)
print(r.status_code)
print(r.text)
for i in r_dict:
print("key:", i,"val",r_dict[i])
然后我得到这个错误:
{'类型': 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/', 'title': '资源未找到', 'status': 404, 'detail': '请求的 找不到资源。','实例': '13af7a5e-9868-4dd3-abd6-6c3b0b58983f'} 404 {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"资源 Not Found","status":404,"detail":"请求的资源不能被 找到。","instance":"13af7a5e-9868-4dd3-abd6-6c3b0b58983f"} 键:类型 值 http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ 键:title val Resource Not Found 键:status val 404 键:detail val 找不到请求的资源。键:实例值 13af7a5e-9868-4dd3-abd6-6c3b0b58983f"
谁能帮我我应该如何指定参数,因为我想那里有错误?
【问题讨论】:
标签: python api python-requests mailchimp mailchimp-api-v3