【问题标题】:Fetch data from ZOHO CREATOR API with python using requests library使用请求库使用 python 从 ZOHO CREATOR API 获取数据
【发布时间】:2020-01-05 18:58:15
【问题描述】:

我正在尝试使用带有请求的 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>

【问题讨论】:

    标签: python html python-requests zoho


    【解决方案1】:

    我在使用带有 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
    

    【讨论】:

      【解决方案2】:

      不需要 urllib,requests 会为你处理:

      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
      

      【讨论】:

        猜你喜欢
        • 2017-11-15
        • 1970-01-01
        • 2019-04-29
        • 2020-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-23
        • 1970-01-01
        相关资源
        最近更新 更多