2011-09-21 3 views
2

임 이메일을 보내려고 비눗물을 통해 Exchange 2010의 비누 전화 : 잘 인증 할 수있어교환 웹 서비스 (EWS) - 비눗물 0.4.1 사용하여 Exchange 웹 서비스를 통해

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>[email protected]</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 

을, 그러나 나는 계속 다음 오류가 발생했습니다 :

Traceback (most recent call last): 
    File "soap.py", line 10, in <module> 
    c = Client(url, transport=ntlm) 
    File "build\bdist.win32\egg\suds\client.py", line 112, in __init__ 
    File "build\bdist.win32\egg\suds\reader.py", line 152, in open 
    File "build\bdist.win32\egg\suds\wsdl.py", line 159, in __init__ 
    File "build\bdist.win32\egg\suds\wsdl.py", line 220, in build_schema 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 93, in load 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 305, in open_imports 
    File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 542, in open 
    File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 563, in download 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 397, in instance 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 226, in __init__ 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 305, in open_imports 
    File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 542, in open 
    File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 563, in download 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 397, in instance 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 226, in __init__ 
    File "build\bdist.win32\egg\suds\xsd\schema.py", line 305, in open_imports 
    File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 542, in open 
    File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 560, in download 
    File "build\bdist.win32\egg\suds\reader.py", line 79, in open 
    File "build\bdist.win32\egg\suds\reader.py", line 95, in download 
    File "build\bdist.win32\egg\suds\transport\https.py", line 60, in open 
    File "build\bdist.win32\egg\suds\transport\http.py", line 62, in open 
    File "build\bdist.win32\egg\suds\transport\http.py", line 118, in u2open 
    File "C:\Python26\lib\urllib2.py", line 391, in open 
    response = self._open(req, data) 
    File "C:\Python26\lib\urllib2.py", line 409, in _open 
    '_open', req) 
    File "C:\Python26\lib\urllib2.py", line 369, in _call_chain 
    result = func(*args) 
    File "C:\Python26\lib\urllib2.py", line 1170, in http_open 
    return self.do_open(httplib.HTTPConnection, req) 
    File "C:\Python26\lib\urllib2.py", line 1143, in do_open 
    r = h.getresponse() 
    File "C:\Python26\lib\httplib.py", line 990, in getresponse 
    response.begin() 
    File "C:\Python26\lib\httplib.py", line 391, in begin 
    version, status, reason = self._read_status() 
    File "C:\Python26\lib\httplib.py", line 355, in _read_status 
    raise BadStatusLine(line) 
httplib.BadStatusLine 

모든 조언을 주시면 감사하겠습니다. 감사합니다.

+0

전체 SUDS 로깅을 설정하면 오류의 원인을 정확히 알 수 있습니다. 비슷한 문제가 있었는데 과부하 된 www.w3.org 서버가 문제였습니다. 해결책은 www.w3.org 스키마에 정적 캐시를 사용하는 것이 었습니다. 이 답변보기 : http://stackoverflow.com/a/8562410/3571 – codeape

답변

1

이 문제가 발생했습니다. 그러나이 오류는 간헐적으로 만 발생합니다. 가능한 해결책을 언급하는 또 다른 게시물을 찾았습니다. 일부는 도움이되었지만 오류를 완전히 해결하지는 못했습니다.

유효한 응답을 보내기 전에 Exchange 서버가 연결을 닫는 것 같습니다. 다른 사람이 더 추가 할 수 있다면 크게 감사하겠습니다. 이 하나가 날 미치게했습니다. 당신은 이미 그 일을하는 경우 urllib2 is throwing an error for an url , while it's opening properly in browser

잘 모르겠어요,하지만 난 messages.xsd, types.xsd 다운로드 설치 내 스크립트를 필요로하고, 서비스 :

아마도이 당신을 도울 수 있습니다 .wsdl을 로컬로 설치하고 패치하십시오. 다음과 같습니다 :

def setup(self): 
    '''Patches the WSDL file to include a service tag. Returns path to 
    local WSDL file.''' 
    trans = self.transport 
    try: 
     makedirs(self.localdir) 
    except OSError: 
     # Directory already exists 
     pass 

    # Download messags.xsd file 
    messages_url = '%s/messages.xsd' % self.urlprefix 
    with open('%s/%s' % (self.localdir, 'messages.xsd'), 'w') as msg_xsd: 
     msg_xsd.write(trans.geturl(messages_url, trans.authtype)) 

    # Download types.xsd file 
    types_url = '%s/types.xsd' % self.urlprefix 
    with open('%s/%s' % (self.localdir, 'types.xsd'), 'w') as types_xsd: 
     types_xsd.write(trans.geturl(types_url, trans.authtype)) 

    # Modify WSDL to add service description 
    service_url = '%s/Exchange.asmx' % self.urlprefix 
    servicexml = ''' 
     <wsdl:service name="ExchangeServices"> 
      <wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding"> 
        <soap:address location="%s"/> 
       </wsdl:port> 
      </wsdl:service> 
     </wsdl:definitions>''' % service_url 
    localwsdl = '%s/%s' % (self.localdir, 'Services.wsdl') 
    wsdlxml = trans.geturl(self.wsdl, trans.authtype) 
    with open(localwsdl, 'w') as wsdl: 
     wsdl.write(wsdlxml.replace('</wsdl:definitions>', servicexml)) 

    return localwsdl 

바라기를 이것은 올바른 방향으로 당신을 가리킬 것입니다. 단순히 거품으로 Exchange와 대화하는 것은 큰 도전이었습니다.

http://lists.fedoraproject.org/pipermail/suds/2010-September/001144.html

업데이트 : RequestServerVersion와 올바른 SOAP 헤더를 보내기 : 나는 '

<?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope> 
    <soap:Header> 
     <t:RequestServerVersion Version="Exchange2010"/> 
    </soap:Header> 
    <soap:Body> 
    </soap:Body> 
</soap:Envelope> 

여기 도움뿐만 아니라, 내 프로젝트에 대한 기반을 제공 한 샘플 코드 발견 간결함을 위해 xml을 잘라 버렸습니다.

+0

프로젝트에 사용한 demo.py 및 Exchange.py 스크립트에 대한 링크를 발견했습니다. [link] http://web.archiveorange.com/archive/v/QOiOM0hVaQTkgK3oG6 – serialworm

+0

왜 이런 일이 발생했는지 알았습니다. suds 클라이언트가 초기화 될 때처럼 http://www.w3.org/2001/xml.xsd에서 스키마 정의를 다운로드합니다. w3.org에서 스키마 파일을 가져와야하는 웹 응용 프로그램이 늘어남에 따라 서버가 시간 초과되어 빈 응답을 반환합니다. 스키마 정의를 로컬에서 캐시하는 것이 제안되었습니다. 희망이 도움이됩니다. http://lists.w3.org/Archives/Public/site-comments/2011Apr/0026.html – serialworm

+0

정말 고맙습니다. 제공하신 모든 정보에 진심으로 감사드립니다. 나는 이것을 며칠 동안 애써왔다. 코드 주셔서 감사하지만 이미 사용하고 있습니다. demo.py 및 Exchange.py에 대해 제안한 것과 동일한 링크에서 가져 왔습니다. 문제는 항상 BadStatusLine을 얻는 것입니다. 한 번만 작동하지 않습니다. –

관련 문제