I am writing a Python scripts to hit an API with keys and get json data, then it should parse the json data for particular value and using those value it will hit the API again in a for loop for getting another json data, then parse it and mail to concern people. This is my project in Python.
This is as far I got with help from @skagra_dragneel . I have been reading multiple posts about Python and json parse but none of them is working.
import ConfigParser
import json
import requests
from pprint import pprint
import urllib
# Read the credentials from File (Not Using those here in raw format)
Config = ConfigParser.ConfigParser()
Config.read('C:/Users/admin/source/repos/MyProject/MyProject/config.ini')
Username = Config.get('credentials', 'Username')
Password = Config.get('credentials', 'Password')
# Get Request for the json output
def apicall():
request_url = 'https://example.com/admin/api/v1/list'
headers = {'X-ApiKeys' : 'accessKey=' + Username + '; secretKey=' + Password}
result = requests.get(request_url,headers=headers).json()
print result;
apicall()
And here below is my output when run.
[{u'size': u'72980725', u'status': u'ready', u'repo_id': u'abc', u'name': u'repo1', u'created_at': u'2018-03-08T10:03:36.965Z', u'updated_at': u'2018-03-10T12:56:40.294Z', u'platform': u'Docker', u'score': u'0.0', u'number_of_vulnerabilities': u'0', u'id': u'yyyy', u'digest': u'sha256:xxxx', u'repo_name': u'repo1'}, {u'size': u'67191884', u'status': u'ready', u'repo_id': u'xyz', u'name': u'repo2', u'created_at': u'2018-03-08T09:56:16.554Z', u'updated_at': u'2018-03-10T12:09:27.963Z', u'platform': u'Docker', u'score': u'6.0', u'number_of_vulnerabilities': u'18', u'id': u'-xyz', u'digest': u'sha256:xxxx', u'repo_name': u'repo2'}]
When pasting the output in json validator, it shows "Invalid Json". Any idea how to complete this project ?
Edit : I edited the print statement for printing the "id" value from json output according to Python: json.loads returns items prefixing with 'u' but it is printing only one value not both of them.