我正在尝试使用 Jupyter (Anaconda) 和 Requests 包与我的 Marketo 实例对话。我可以创建身份验证 token ,但在对端点进行实际调用时遇到了困难。
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列(字符0)
有趣的是,我可以单击 print() 中的 URL,这会将我带到浏览器中的 JSON 响应。
最佳答案
我认为问题在于如何组装 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)
它应该可以正常工作。
关于Python 请求 + Marketo REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52340758/