Dec-19-2019, 12:46 PM
in curls you have a dict, not set
so
so
#!/usr/bin/env python3 .. with open('/tmp/config.json') as json_file1: data1 = json.load(json_file1) for domaine, value in data1.items(): for name, value2 in value.items(): service = data1[domaine][name]['service'] threshold1, threshold2 = data1[domaine][name]['threshold'] # unpack the list try: url = "https://localhost:5665/v1/objects/hosts/" request_url = url+hostname headers = { 'Accept': 'application/json', 'X-HTTP-Method-Override': 'PUT' } data = { "templates": service, "attrs": { "address":"BLABLA", "zone":"BLIBLI", "vars": {'threshold1':threshold1, 'threshold2':threshold2} } } r = requests.post(request_url, headers=headers, verify=False, auth=('admin', 'XXXXXXXXXXXXXXXXXX'), data=json.dumps(data))note that in curl threshold1 and threshold2 are integers, you will read them as str, so you may need to explicitly convert them
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs