My function returns a string value which I have assigned to variables. I am converting it to json and I want to return the value of 'printer_id'
Code :
import json
def getprinterid():
s='''
{
"printer_config": {
"printer_id": "AQAAAAFhvL8CXQ",
"conn_config_url": "https://connectivity",
"printer_caps_url": "https://deviceconfig",
"cred_refresh_url": "https://registration"
}
,"cloud_config": {
"eprint_enabled": true,
"sips_enabled": true,
"mobile_print_enabled": true
}
}
'''
decodedinfo = json.loads(s)
for x in decodedinfo:
if x == "printer_config":
for y in decodedinfo[x]:
if y == "printer_id":
return decodedinfo[x][y]
Added the curly braces , Test runs successfully now , Output:=========================== 1 passed in 0.01 seconds =========================== Process finished with exit code 0