Python 请求 + Marketo REST API

标签 python rest python-requests anaconda marketo

我正在尝试使用 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/

相关文章:

python - 创建与 EXCEL OFFSET 函数等效的 pandas 函数

rest - 用于获取完整用户列表的 Jira Rest Api

php - mcrypt 是否支持非对称加密?

python - 使用python请求增加504超时之前的时间

python - 为什么我在尝试网页抓取时不断遇到 "Type Error"问题?

python - 是否可以增加 Google App Engine 中的响应超时?

Python 猜谜游戏——if vs while

python - Pandas read_html 返回原始 HTML 内容[对于某些行/单元格/等]

java - 我的 Java 服务器和本地客户端之间的通信

python - "requests.exceptions.ConnectionError: (' 连接中止。 ', RemoteDisconnected(' 远端关闭连接无响应 ',))"