Python Forum
Object of type set is not JSON serializable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object of type set is not JSON serializable
#4
in curls you have a dict, not set
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

Reply


Messages In This Thread
RE: Object of type set is not JSON serializable - by buran - Dec-19-2019, 12:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  declaring object parameters with type JonWayn 2 917 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  Deserialize Complex Json to object using Marshmallow tlopezdh 2 2,143 Dec-09-2021, 06:44 PM
Last Post: tlopezdh
Star Type Error: 'in' object is not callable nman52 3 3,441 May-01-2021, 11:03 PM
Last Post: nman52
  finding and deleting json object GrahamL 1 4,860 Dec-10-2020, 04:11 PM
Last Post: bowlofred
  Serializable JarredAwesome 4 2,262 Nov-19-2020, 11:50 PM
Last Post: JarredAwesome
  TypeError: 'type' object is not subscriptable Stef 1 4,560 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  isinstance() always return true for object type check Yoki91 2 2,589 Jul-22-2020, 06:52 PM
Last Post: Yoki91
  AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__ binhduonggttn 0 2,258 Feb-19-2020, 11:29 AM
Last Post: binhduonggttn
  Type hinting - return type based on parameter micseydel 2 2,519 Jan-14-2020, 01:20 AM
Last Post: micseydel
  type of object as a string Skaperen 1 2,309 Dec-02-2019, 08:01 AM
Last Post: midarq

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020