I am trying to read API.
The following python code works:
import requests
import json
url = '.....'
headers = {
'accept': 'application/json',
'SY-API-KEY': '.....',
'Content-Type': 'application/json',
}
json_data = {
'ingress_id': '.....'
}
response = requests.post(url, headers=headers, json=json_data)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
I tried to migrate them to ignition script with the following script.
import system
url = '.....'
headers = {
'accept': 'application/json',
'SY-API-KEY': '.....',
'Content-Type': 'application/json',
}
json_data = {
'ingress_id': '.....'
}
response = urllib2.Request(url, headers=headers, data=json_data)
contents = urllib2.urlopen(response).read()
data = system.util.jsonDecode(response)
print(data)
It showed error at the following step:
contents = urllib2.urlopen(response).read()
My question is: How do I realize the following function in ignition?
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))