0

我正在寻找一个将运行 URL 的 python 程序。很简单,它只需要使用提供的凭据运行应用程序生成的 URL 即可访问应用程序。我将安排每晚运行 python 脚本。

我有一个生成 URL 的应用程序。如果我运行该 URL,它将生成 JSON 文件。

我正在尝试预先缓存应用程序的输出,所以我想每天早上运行 URL。

以下是资料:

USERNAME = "test"
PASSWORD = "test5"
HOST = 'appl.xyz.net' 
PORT = 8080

示例 URL 为: http ://appl.xyz.net:8080/app/content/pq/doQuery?solution=nd&path=&file=Test.nd&dataAccessId=1¶mid=4221

JSON:

{
   "queryInfo":{
      "totalRows":"3"
   },
   "resultset":[
      [
         4215,
         null,
         "AAA"
      ],
      [
         4215,
         null,
         "BBB"
      ]
   ],
   "metadata":[
      {
         "colIndex":0,
         "colType":"Numeric",
         "colName":"id"
      },
      {
         "colIndex":1,
         "colType":"String",
         "colName":"Name"
      },
      {
         "colIndex":2,
         "colType":"String",
         "colName":"City"
      }
   ]
}

谢谢

4

1 回答 1

1

使用python-requests图书馆。

那么你需要做的就是:

import requests

url = 'http://appl.xyz.net:8080/app/content/pq/doQuery?solution=nd&path=&file=Test.nd&dataAccessId=1&paramid=4221'
user = 'test'
password = 'test5'

# Takes care of the HTTP authentication
data = requests.get(url, auth=(user, password))
json_data = data.json()

StvnW如果您不想安装任何其他库,在 Python 中的 CURL 替代方案的注释中提供了一个链接。

于 2013-10-17T16:03:48.040 回答