Python请求+ Marketo REST API

问题描述 投票:2回答:1

我正在尝试使用Jupyter(Anaconda)和Requests包与我的Marketo实例交谈。我可以创建auth令牌,但是却无法对端点进行实际调用。

host = "https://my_mtko_instance.com"    
leadId = "13000000"
endpoint = "/rest/v1/lead/" + leadId + ".json"
auth_token =  "?access_token=" + mkto_token
getLead = requests.get(host+endpoint+leadId+auth_token)
print(host+endpoint+auth_token)
getLead.json()

我得到一个`JSONDecodeError:期望值:第1行第1列(char 0)

有趣的是,我可以从print()中单击URL,这会让我在浏览器中看到一个JSON查找响应。

python rest python-requests anaconda marketo
1个回答
2
投票

我认为问题在于你如何组装get请求的url。

请注意,端点的正确格式为: https://<mkto_instance>.mktorest.com/rest/v1/lead/{leadId}.json 但是,使用host+endpoint+leadId+auth_token格式,您插入leadId变量两次,因为endpoint变量已经包含它。

将调用更改为requests.get(host+endpoint+auth_token),它应该可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.