0

我只是尝试使用 Alex Koshelev 的 EWS 特定的泡沫分支(可以在BitBucket上找到)使用 Python 访问 Exchange Web Services (EWS) 2010 。我在这里找到了访问 EWS 的基本代码,到目前为止它运行良好。但是,当我尝试实现需要属性的其他操作(如 FindFolder 操作)时,它会失败。

这是我正在使用的代码:

import urllib2    

from suds.client import Client
from suds.sax.element import Element
from suds.transport.https import HttpTransport

class Transport(HttpTransport):
    def __init__(self, **kwargs):
        realm, uri = kwargs.pop('realm'), kwargs.pop('uri')
        HttpTransport.__init__(self, **kwargs)
        self.handler = urllib2.HTTPBasicAuthHandler()
        self.handler.add_password(realm=realm,
                                  user=self.options.username,
                                  passwd=self.options.password,
                                  uri=uri)
        self.urlopener = urllib2.build_opener(self.handler)

transport = Transport(realm='owa10.123together.com',
                      uri='https://owa10.123together.com',
                      username='demo10@owatest10.123together.com',
                      password='demo123!')
client = Client("https://owa10.123together.com/EWS/Services.wsdl",
                transport=transport) 

ns = ('t', 'http://schemas.microsoft.com/exchange/services/2006/types')

soap_headers = Element('RequestServerVersion', ns=ns)
soap_headers.attributes.append('Version="Exchange2010_SP1"') 
client.set_options(soapheaders=soap_headers)

address = client.factory.create('t:EmailAddress')
address.Address = 'demo10@owatest10.123together.com'

traversal = client.factory.create('t:FolderQueryTraversalType')
#traversal.Traversal = 'Deep'

#print client.service.GetUserOofSettings(address)
test =  client.service.FindFolder(traversal)
print test

当我运行此代码时,我收到以下错误:

suds.TypeNotFound: Type not found: 'Shallow'

我还使用了记录器来找出问题所在,它向我展示了以下内容:

DEBUG:suds.mx.literal:starting content:
(Content){
   tag = "Shallow"
   value = "Shallow"
   type = None
 }

有人知道这里的问题在哪里吗?是我的一段代码还是 .wsdl 文件不行?请注意,我对 Python 非常熟悉,尤其是 suds。如果您需要更多信息或代码,请告诉我。

非常感谢您!

4