I've made some progress, changed the way I make API call., but still having issues with displaying data in splunk. this is part of my code and error message i'm getting. Not sure how to resolve issue?
import requests
import csv
import json
import sys
try: from splunklib.results import *
except: print(sys.exc_info())
try: import httplib
except: print(sys.exc_info())
try: import urllib
except: print(sys.exc_info())
payload = {
"application": [
"app_name",
"description",
"top_app",
"status",
"app_type",
"gaca_ref",
"created_on",
"modified_on",
"alias_name",
"business_segment",
"business_solution",
"lob",
"schd_maintenance",
"schd_outage",
"vendor_contract",
"vendor_name",
"platforms",
"products",
"clients",
"countries"
],
"fields": "custom",
"uaid_list": ['']}
def getAppMapApplication(uaid_num, user_name, pass_word):
payload['uaid_list'] = [uaid_num]
data = loadInputCredentials(user_name, pass_word)
token = getTokenId(data)
url2 = "/api/v3/appmap/applications/?format=json&username=abbr3f5&api_token=" + token
conn = httplib.HTTPSConnection("echo.1dc.com")
try: conn.request("POST", url2, json.dumps(payload))
except: print(sys.exc_info())
try: response = conn.getresponse()
except: print(sys.exc_info())
temp = response.read()
conn.close()
try: reader = results.ResultsReader(response)
except: print(sys.exc_info())
for result in reader:
print("print result", result.keys())
if isinstance(result, dict):
print("Result: %s" % result)
elif isinstance(result, Message):
print("Message: %s" % result)
print("is_preview = %s " % reader.is_preview)
return response
error message i'm getting:
(<type 'exceptions.NameError'>, NameError("global name 'results' is not defined",), <traceback object at 0x0000000002DB9908>)
Traceback (most recent call last):
File "C:/Users/tajones/PycharmProjects/appMapAPI/API_calls.py", line 296, in <module>
main(sys.argv)
File "C:/Users/tajones/PycharmProjects/appMapAPI/API_calls.py", line 291, in main
getAppMapApplication(args[2],args[3],args[4])
File "C:/Users/tajones/PycharmProjects/appMapAPI/API_calls.py", line 195, in getAppMapApplication
for result in reader:
UnboundLocalError: local variable 'reader' referenced before assignment
Process finished with exit code 1