Python 请求 + Marketo REST API

Python Requests + Marketo REST API

我正在尝试使用 Jupyter (Anaconda) 和 Requests 包与我的 Marketo 实例通信。我可以创建身份验证令牌,但无法对端点进行实际调用。

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 外观响应。

我认为问题在于您如何 assemble url 获取请求。

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

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