I was wondering if you could help me with a piece of code i'm working on at the moment. I'm new to Python and this is one of the first major scripts i have tried to write.
import json, sys
from pprint import pprint
#Importing workbench json output into the python script.
with open('jsonoutput.json') as data_file:
data = json.load(data_file)
#Sets the verible for the while loop.
x = int(0)
while x <= 1:
y = x
print type(data)
jdata = data["result"]["items"][y]["tagValues"]["IdDevicesMap"]["value"]
if setup_1(jdata) == True:
Default_1 += 1
else:
print "exiting"
Error i get when it runs:
Traceback (most recent call last):
File "main.py", line 47, in <module>
jdata = data["result"]["items"][y]["tagValues"]["IdDevicesMap"]["value"]
KeyError: 'tagValues'
Just on a side note as well, when i manually put in the list number [y] to 1 the code runs perfectly. So it's like its got an issue with the way I'm inputting the variable [y] into the request.