我正在尝试使用suds 0.4.1通过Exchange Web服务发送电子邮件:
import suds
from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
url = "file:///C:/Services.wsdl"
user = 'domain\\user'
password = "hardtoguess"
ntlm = WindowsHttpAuthenticated(username=user,password=password)
c = Client(url, transport=ntlm)
xml = ''' <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <CreateItem
MessageDisposition="SendAndSaveCopy"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<SavedItemFolderId> <DistinguishedFolderId Id="sentitems"
xmlns="http://schemas.microsoft.com/exchange/services/2006/types"/>
</SavedItemFolderId> <Items> <Message
xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemClass>IPM.Note</ItemClass> <Subject>Sent via Python->Exchange->EWS</Subject>
<Body BodyType="Text">This message has been sent to you via Python,
Exchange and EWS :)</Body> <ToRecipients> <Mailbox>
<EmailAddress>imran.azad@localhost</EmailAddress> </Mailbox> </ToRecipients>
</Message> </Items>
</CreateItem> </soap:Body></soap:Envelope>'''
attr = c.service.CreateItem(__inject={'msg':xml})
xml = ''' <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <soap:Body>
<ResolveNames
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
ReturnFullContactData="true"> <UnresolvedEntry>azadi</UnresolvedEntry>
</ResolveNames> </soap:Body> </soap:Envelope> '''
attr = c.service.ResolveNames(__inject={'msg':t})
print attr
我可以很好地进行身份验证,但是我一直收到以下错误:
^{pr2}$任何建议都将不胜感激。谢谢
我也经历过这个问题。但是,我只是间歇性地得到这个错误。我发现另一篇文章提到了一个可能的解决方案,它对一些人有帮助(我得到的错误更少),但它并没有完全解决这个问题。在
问题似乎是Exchange服务器在发送有效响应之前关闭了连接。如果其他人能补充更多,我将不胜感激。这个让我抓狂了。在
或许这可以帮助您: urllib2 is throwing an error for an url , while it's opening properly in browser
我不确定你是否已经在做了,但是我需要设置我的脚本来下载xsd消息, 类型.xsd,以及服务.wsdl局部修补。包括以下内容:
希望这能给你指明正确的方向。简单地用肥皂水交流是一个很大的挑战。我在这里找到了一些帮助,以及为我的项目提供基础的示例代码:
http://lists.fedoraproject.org/pipermail/suds/2010-September/001144.html
更新: 使用RequestServerVersion发送正确的SOAP头:
^{pr2}$为了简洁起见,我截断了xml。在
相关问题 更多 >
编程相关推荐