Exchange EWS 2010上的Python suds.TypeNotFound

时间:2013-04-26 08:17:53

标签: python web-services exchange-server exchangewebservices suds

我只是尝试使用Alex Koshelev的EWS特定分支(可以在BitBucket上找到)使用Python访问Exchange Web服务(EWS)2010。 我找到了访问EWS here的基本代码,到目前为止工作正常。但是,当我尝试实现需要属性的其他操作(如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的血腥,尤其是肥皂水。如果您需要更多信息或代码,请告诉我。

非常感谢你!