Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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
使用RESTAPI从python中的office365读取未打开的邮件_Python_Rest_Exchangewebservices_Office365 - Fatal编程技术网

使用RESTAPI从python中的office365读取未打开的邮件

使用RESTAPI从python中的office365读取未打开的邮件,python,rest,exchangewebservices,office365,Python,Rest,Exchangewebservices,Office365,如何使用REST请求从python(v2.6)中的office365获取所有未打开的邮件(元数据和内容,包括附件)?已注释的页面值正在返回urllib2.HTTPError:HTTP错误400:Bad请求,而未注释的页面值工作正常。谢谢 import urllib import urllib2 #page = 'https://outlook.office365.com/ews/odata/Me/Inbox/Messages?$filter=IsRead' page = 'https://ou

如何使用REST请求从python(v2.6)中的office365获取所有未打开的邮件(元数据和内容,包括附件)?已注释的页面值正在返回urllib2.HTTPError:HTTP错误400:Bad请求,而未注释的页面值工作正常。谢谢

import urllib
import urllib2

#page = 'https://outlook.office365.com/ews/odata/Me/Inbox/Messages?$filter=IsRead'
page = 'https://outlook.office365.com/ews/odata/Me/Inbox/Messages'
username = "myusername"
password = "mypassword"

p = urllib2.HTTPPasswordMgrWithDefaultRealm()
p.add_password(realm='', uri=page, user=username, passwd=password)
handler = urllib2.HTTPBasicAuthHandler(p)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)

response = urllib2.urlopen(page)
print(response.read())

您可以通过SOAP使用EWS来获取此信息,但是创建SOAP请求将比使用新的Office 365 REST API更加复杂,尤其是来自Python的

请参阅此链接:

因此,为了从收件箱中获取所有未读的电子邮件,您可以发出如下请求(未测试):

如果坚持使用香草EWS,则可以使用FindItem操作


谢谢!现在,您是否知道我将如何在上面的代码中传递建议的参数“eq false HTTP/1.1”?如果不清楚,很抱歉,eq false是查询字符串的一部分,HTTP/1.1只是表示您正在发出HTTP 1.1请求:)正确的页面变量为:“”。再次感谢朴先生的帮助!
GET https://outlook.office365.com/ews/odata/Me/Inbox/Messages?$filter=IsRead eq false HTTP/1.1
Accept: application/json;odata.metadata=full