Привет всем, я читаю из этого текстового файла, который имеет все поля, которые я хочу
{"Tables":
[
{
"Name": "Event",
"EventType": "Summary",
"Fields": "*",
"SortBy": "WhenOccurred",
"SortType": "Date",
"Last": "01/14/2020 16:02:00 -05:00"
},
{
"Name": "Event",
"EventType": "Account",
"Fields": "*",
"SortBy": "WhenOccurred",
"SortType": "Date",
"Last": "01/14/2020 16:02:00 -05:00"
},
{
"Name": "Event",
"EventType": "Agent",
"Fields": "*",
"SortBy": "WhenOccurred",
"SortType": "Date",
"Last": "01/14/2020 16:02:00 -05:00"
},
{
"Name": "Event",
"EventType": "Server",
"Fields": "*",
"SortBy": "WhenOccurred",
"SortType": "Date",
"Last": "01/14/2020 16:02:00 -05:00"
},
{
"Name": "ADUser",
"Fields": "*",
"SortBy": "",
"SortType": "None"
}
]
}
Я использую logi c, который проходит через все поля и ввод ответ на запрос get json параметр
with open('tables.txt') as json_file:
data = json.load(json_file)
for p in data['Tables']:
tableName = p['Name']
sortBy = p['SortBy']
lastGot = p['Last']
fields = p['Fields']
sortType = p['SortType']
eventType = p['EventType']
fileName = ""
sql = ""
if (tableName == 'Event'):
sql = "SELECT " + fields + " FROM " + tableName + " WHERE Event.EventType IN ('" + eventType + "') AND " + tableName + "." + sortBy + " > DateFunc('" + lastGot + "') ORDER BY " + tableName + "." + sortBy + ";"
fileName = "Event-" + eventType
else:
if (sortType == 'None'):
sql = "SELECT " + fields + " FROM " + tableName + ";";
else:
sql = "SELECT " + fields + " FROM " + tableName + " WHERE " + tableName + "." + sortBy + " > DateFunc('" + lastGot + "') ORDER BY " + tableName + "." + sortBy + ";"
fileName = tableName
event_data = sql
#print(event_data)
r = requests.get(url, headers=headers, json={"script": event_data},
verify=verify).json()
reponseobject = r
jsonlist = json.dumps(reponseobject)
print(jsonlist)
Но выдает ошибку, которую я не понимаю, как исправить это, когда все поля, которые я хочу, есть какие-либо предложения?
Traceback (most recent call last):
File "C:/Users/PycharmProjects/Vulnerabilities/main.py", line 31, in <module>
lastGot = p['Last']
KeyError: 'Last'
{'Name': 'Event', 'EventType': 'Summary', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
SELECT * FROM Event WHERE Event.EventType IN ('Summary') AND Event.WhenOccurred > DateFunc('01/14/2020 16:02:00 -05:00') ORDER BY Event.WhenOccurred;
{'Name': 'Event', 'EventType': 'Account', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
SELECT * FROM Event WHERE Event.EventType IN ('Account') AND Event.WhenOccurred > DateFunc('01/14/2020 16:02:00 -05:00') ORDER BY Event.WhenOccurred;
{'Name': 'Event', 'EventType': 'Agent', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
SELECT * FROM Event WHERE Event.EventType IN ('Agent') AND Event.WhenOccurred > DateFunc('01/14/2020 16:02:00 -05:00') ORDER BY Event.WhenOccurred;
{'Name': 'Event', 'EventType': 'server', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
SELECT * FROM Event WHERE Event.EventType IN ('server') AND Event.WhenOccurred > DateFunc('01/14/2020 16:02:00 -05:00') ORDER BY Event.WhenOccurred;
Вот результат, в котором я пытался поймать p
{'Name': 'Event', 'EventType': 'Summary', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
{'Name': 'Event', 'EventType': 'Account', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
{'Name': 'Event', 'EventType': 'Agent', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
{'Name': 'Event', 'EventType': 'server', 'Fields': '*', 'SortBy': 'WhenOccurred', 'SortType': 'Date', 'Last': '01/14/2020 16:02:00 -05:00'}
error occurred