Reputation: 783
I am looking for a python program which will run the URL. Simple, it just needs to run the URL produced from the application with provided credentials to access the application. I will schedule to run the python script every night.
I have an application that produces the URL. If I run that URL, it will produce the JSON file.
I am trying to pre-cache the output of the application so I want to run the URL every morning.
Below are the information:
USERNAME = "test"
PASSWORD = "test5"
HOST = 'appl.xyz.net'
PORT = 8080
Sample URL is: 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"
}
]
}
Thanks
Upvotes: 0
Views: 130
Reputation: 15058
Use the python-requests
library.
Then all you need to do is:
import requests
url = 'http://appl.xyz.net:8080/app/content/pq/doQuery?solution=nd&path=&file=Test.nd&dataAccessId=1¶mid=4221'
user = 'test'
password = 'test5'
# Takes care of the HTTP authentication
data = requests.get(url, auth=(user, password))
json_data = data.json()
StvnW
has provided a link in the comments to CURL alternative in Python if you do not wish to install any other libraries.
Upvotes: 1