Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Django、请求和Microsoft Graph将数据发布到Outlook日历_Python_Django_Python Requests_Microsoft Graph Api_Microsoft Graph Calendar - Fatal编程技术网

Python 使用Django、请求和Microsoft Graph将数据发布到Outlook日历

Python 使用Django、请求和Microsoft Graph将数据发布到Outlook日历,python,django,python-requests,microsoft-graph-api,microsoft-graph-calendar,Python,Django,Python Requests,Microsoft Graph Api,Microsoft Graph Calendar,我有一个函数,我试图使用Microsoft的Graph API向outlook日历发出post请求 def create_calendar_eventtoken,有效负载,**kwargs: 创建新的日历事件 :param有效负载:json str :param标记:str :return:dict graph_client=OAuth2Sessiontoken=token url\u端点=https://graph.microsoft.com/v1.0/me/events events=gra

我有一个函数,我试图使用Microsoft的Graph API向outlook日历发出post请求

def create_calendar_eventtoken,有效负载,**kwargs: 创建新的日历事件 :param有效负载:json str :param标记:str :return:dict graph_client=OAuth2Sessiontoken=token url\u端点=https://graph.microsoft.com/v1.0/me/events events=graph\u client.postrl=url\u endpoint,json=payload returnevents.json 在我看来,我正在使用一个表单从用户那里获取数据,这样我就可以反过来将用户数据发布到我的Outlook日历中。该表单如下所示:

类CalendarFormViewTemplateView: template_name=event-form.html def getself,请求,**kwargs: 表单=日历事件表单 返回renderrequest,self.template_name,{form:form} def postself,请求: form=CalendarEventFormrequest.POST token=client.get\u tokenrequest未正确获取令牌 如果form.u有效: 主题=表格。数据[主题] 内容=表单。已清理的\u数据[正文\u内容] 开始=表单。已清理的\u数据[开始] 结束=表单。已清理的\u数据[结束] 位置=表单。已清理的\u数据[位置] is_all_day=表单。已清理的数据[is_all_day] 有效载荷={ 主题:主题,, 正文:{contentType:html,content:content}, “开始”:{ 日期时间:开始。strftime%Y-%m-%dT%H:%m:%S.%f, 时区:UTC, }, 完:{ 日期时间:结束。strftime%Y-%m-%dT%H:%m:%S.%f, 时区:UTC, }, 位置:{displayName:location}, isAllDay:你一整天都在吗, } event=create\u calendar\u eventtoken,json.dumpspayload 打印事件 返回renderrequest,self.template\u名称,context=event 返回renderrequest,event-form.html,{form:form} 我正在将access_令牌和表单数据正确地传递到有效负载字典中,但是,当我打印出事件时,我收到以下错误消息:

{u'error':{u'innerror':{u'date':u'2020-01-20T21:59:24',u'request-id':u'fxbxd5c1-myxx-reqx-idxx-1xxxab91a'},u'message':u'Empty Payload.JSON content预期',u'code':u'BadRequest'} Azure/Microsoft图形端的所有内容都已正确设置。我可以在使用时获取日历事件和POST请求。问题只在于从Django应用程序将事件发布到我的日历中


有没有想过我会错在哪里?

我永远都不明白为什么要花时间写一篇关于stackoverflow的文章,然后才能神奇地找到答案

问题出在我的post功能中:

event=create\u calendar\u eventtoken,json.dumpspayload 我应该传递dict,而不是json作为有效负载。将json.dumpspayload替换为有效负载就可以做到这一点。事件应如下所示:

event=create_calendar_eventtoken,有效负载从有效负载中删除json.dumps