Python / Json - KeyError' Body'在创作时

时间:2016-12-01 15:19:32

标签: python json

我得到了错误

var state = {
  lastMessage: {
    owner: 'lastMessageOwnerID'
  },
  owner: 'currentMessageOwnerID'
}

function isSameMessageOwner ({ lastMessage, owner: currentMessage: { owner } }) {
  return lastMessage.owner === currentMessage.owner
}

var isSameOwner = isSameMessageOwner(state)

对于下面的代码,我是json的新手,所以不明白为什么这不起作用。所有其他工作但我看到身体上的错误,是因为我使用两个[]? 这将被发送到office 365 API,因此它期望它采用这种格式。

由于

>>> appt = CreateEvent(authentication, result[0].calendarId, subject_text, start_time, end_time, subscribers, content)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 9, in CreateEvent
KeyError: 'Body'

1 个答案:

答案 0 :(得分:3)

首先需要在Body文件中提供data密钥。您可以像这样解决您的问题:

data = {'Body': {}}

data['Subject'] = subject
data['Start'] = start_time
data['End'] = end_time
data['Attendees'] = attendees
data['Body']['Content'] = content
data['Body']['ContentType'] = 'Text'
# ...