0

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&paramid=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

1 Answer 1

1

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&paramid=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.

Sign up to request clarification or add additional context in comments.

8 Comments

where should I enter credentials?
Read the requests documentation. But I've updated my answer to include the HTTP authentication.
More related discussion and examples, including comparisons between requests and urllib2 : stackoverflow.com/questions/2667509/curl-alternative-in-python/… stackoverflow.com/questions/2018026/…
Can you show me how to do without installing library (e.g. using import urllib2) because I could not install it in windows.I did "setup.py install" in cmd prompt.
Try it yourself using the link @StvnW posted in the comments and me in the question. Also look at using easy_install or pip on Windows to help install packages. Also what was the output of setup.py install? Try and work out why it's not installing.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.