Office 365 REST API(Python)将电子邮件标记为已读
我肯定我做了一些简单的错误,但我一辈子都不知道如何将“IsRead”属性设置为true。这是我流程的最后一步,它将获取messagesa的筛选列表,并存储和处理任何附件 根据文档,“IsRead”是可写的: 我正在使用python 2.7和请求模块:Office 365 REST API(Python)将电子邮件标记为已读,python,rest,python-2.7,office365,Python,Rest,Python 2.7,Office365,我肯定我做了一些简单的错误,但我一辈子都不知道如何将“IsRead”属性设置为true。这是我流程的最后一步,它将获取messagesa的筛选列表,并存储和处理任何附件 根据文档,“IsRead”是可写的: 我正在使用python 2.7和请求模块: # once file acquired mark the email as read params = {'IsRead':'True'} base_email_url = u'https://outlook.office365.com/api
# once file acquired mark the email as read
params = {'IsRead':'True'}
base_email_url = u'https://outlook.office365.com/api/v1.0/me/messages/{0}'.format( msgId )
response = requests.patch(base_email_url, params, auth=(email,pwd))
log.debug( response )
得到的回应是:
{"error":{"code":"ErrorInvalidRequest","message":"Cannot read the request body."}}
我的请求有什么问题吗?乍一看似乎还可以。我想知道内容类型头是否没有设置为“application/json”或类似的内容。尝试获取网络跟踪,并验证请求是否类似于:
PATCH https://outlook.office365.com/api/v1.0/Me/Messages('msgid') HTTP/1.1
Accept: application/json;odata.metadata=full
Authorization: Bearer <token>
Content-Type: application/json;odata.metadata=full
Host: outlook.office365.com
Content-Length: 24
Expect: 100-continue
Connection: Keep-Alive
{
"IsRead": "true"
}
补丁https://outlook.office365.com/api/v1.0/Me/Messages('msgid')HTTP/1.1
接受:application/json;odata.metadata=full
授权:持票人
内容类型:application/json;odata.metadata=full
主机:outlook.office365.com
内容长度:24
预期:100人继续
连接:保持活力
{
“IsRead”:“正确”
}
我自己有一个答案,这确实是一件简单的事情。
没有充分了解补丁与GET或POST的区别是一个错误。
简言之,确保标题设置为正确的内容类型非常重要
以下是工作代码:
# once file acquired mark the email as read
changes = {u'IsRead':u'True'}
headers = {'Content-Type': 'application/json'}
json_changes = json.dumps(changes)
base_email_url = u'https://outlook.office365.com/api/v1.0/me/messages/{0}'.format( msgId )
response = requests.patch(base_email_url, data=json_changes, auth=__AUTH, headers=headers)
log.debug( response )
哈,我刚把我发现的东西打出来,你说得对,先生。