我正在尝试使用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查找响应。
我认为问题在于你如何组装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)
,它应该可以正常工作。