我正在使用Outlook Webhook Subscriptions并在QA服务器上工作 .
根据Microsoft Graph文档,我们需要发送请求以获取webhook通知 . 我正在使用Python 3请求模块 .
我发送以下数据,但收到错误 . 我无法弄清楚我在这个过程中出错的地方 .
url="https://graph.microsoft.com/v1.0/subscriptions"
header={
'Content-Type': 'application/json',
'Authorization':"Bearer "+ "valid access token"
}
data={
"changeType": "created,updated",
"notificationUrl": "https://qa.example.com/get_webhook",
"resource": "/me/mailfolders('inbox')/messages",
"expirationDateTime": "2018-12-11T11:00:00.0000000Z"
}
response=requests.post(url, headers=header, data=data)
执行上述行后,我收到以下<400>响应
'{\r\n "error": {\r\n "code": "BadRequest",\r\n "message":
"Unable to read JSON request payload. Please ensure Content-Type
header is set and payload is of valid JSON format.",\r\n
"innerError": {\r\n "request-id": "3a15ba2f-a055-4f33-a3f8-
f1f40cdb2d64",\r\n "date": "2018-12-10T06:51:32"\r\n }\r\n
}\r\n}'
2 回答
要以JSON格式发布,您需要
json
属性而不是data
属性(即json={"key": "value"}
:您可以使用: