python-3.x - Outlook Web 挂钩订阅
问题描述
我正在使用 Outlook Webhook 订阅并在 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}'
解决方案
要发布为 JSON,您需要json
属性而不是data
属性(即json={"key": "value"}
:
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, json=data)
推荐阅读
- python - 使用 selenium 登录时出现 405 错误
- javascript - 在 chrome.tabs.query 错误中使用 RegExp 替换时:无法读取未定义的属性“替换”
- mysql - 迁移 - 如何向已填充的表添加 UNIQUE 约束?
- javascript - 如何解决此 Firebase 云功能错误:无法读取属性
- java - 使用字符串和双精度的关系创建树
- android - 无法在分离视图上启动此动画器
- matlab - 获取日期范围内独特季度列表的更快方法
- c++ - 内部类的未解析外部符号
- gradle - Gradle 未将 SNAPSHOT 解析为时间戳
- python - 如何将 curl POST 转换为 Python 中的请求 POST?