当键相同时发布嵌套字典

时间:2020-07-17 04:49:40

标签: python dictionary request nested

我试图在一个名为Toggl的时间跟踪应用程序上发布多个条目,并且这样做,我认为我需要发布一个嵌套字典,但是键值('time_entry')需要保持不变。有人可以帮我弄清楚当密钥需要保持相同时如何发布嵌套字典吗?

代码:


data = { 
    "time_entry": 

        { 
            "description":"LOL Meeting 2",
            "wid":2758150,
            "start":"2020-07-11T14:00:00.000Z",
            "duration":3600,
            "pid":156855752,
            "created_with":"python",
            "tags":["Coaching"],
            
           
        },
        "time_entry":

         
       { 
            "description":"LOL Meeting",
            "wid":2758150,
            "start":"2020-07-11T13:00:00.000Z",
            "duration":3600,
            "pid":156855752,
            "created_with":"python",
            "tags":["Coaching"]
            
        }
       
        
}



response = toggl.postRequest("https://www.toggl.com/api/v8/time_entries", parameters=data)

从这段代码中,您可以期望只提交一个条目,但是我需要两个条目

1 个答案:

答案 0 :(得分:0)

data可能是字典列表,如下所示:

data = [{ 
            "description":"LOL Meeting 2",
            "wid":2758150,
            "start":"2020-07-11T14:00:00.000Z",
            "duration":3600,
            "pid":156855752,
            "created_with":"python",
            "tags":["Coaching"]
        },
           { 
            "description":"LOL Meeting",
            "wid":2758150,
            "start":"2020-07-11T13:00:00.000Z",
            "duration":3600,
            "pid":156855752,
            "created_with":"python",
            "tags":["Coaching"]
            
        }]

如您所见,您将不需要key: time_entry