使用请求库从ZOHO CREATOR API使用python获取数据

时间:2019-09-02 19:48:16

标签: python html python-requests zoho

我正在尝试使用带有请求的Python 3从zoho creator API获取数据。即使我使用python进行一些临时工作和数据散乱,我对http请求也一无所知。谁能帮助我使用请求将以下html代码转换为等效的python代码?

<form method="GET" action="https://creator.zoho.com/api/xml/sample/view/Employee_View">
<input type="hidden" name ="authtoken" value="************">
<input type="hidden" name ="zc_ownername" value="********">
<input type="hidden" name="criteria" value='(PacienteSL=="Abilio Alfredo Finotti")'>
<input type="hidden" name ="scope" id="scope" value="creatorapi">
<input type="submit" value="View Records">
</form>

2 个答案:

答案 0 :(得分:2)

使用urllib请求进行此类调用时,我已经取得了一些成功-类似于下面的内容应该翻译上面的html。

import requests
import urllib

param = urllib.parse.urlencode({"authtoken":"token_here", 
  "scope":"creatorapi",
  "zc_ownername":"owner_here",
  "criteria":'(PacienteSL=="Abilio Alfredo Finotti")'})

url = "https://creator.zoho.com/api/xml/{0}/view/{1}/{2}".format("sample", "Employee_View", param)

requests.get(url).content

答案 1 :(得分:1)

不需要urllib,请求会为您处理:

import requests


url = "https://creator.zoho.com/api/xml/sample/view/Employee_View/"
params = {
    "authtoken": "***",
    "scope": "creatorapi",
    "zc_ownername": "***",
    "criteria": "(PacienteSL==\"Abilio Alfredo Finotti\")"
}

requests.get(url, params=params).content