Search code examples
pythonsoapexchangewebservicessuds

Python EWS GetFolder request is always invalid


Hi Stackoverflow community!

I'm trying to work with Python suds and ewsclient to talk to Exchange. I created a small prog, which seems to send the right soap message, but it is always rejected by the Exchange server.

The python code for this request is on gist.

Soap Message:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Header/>
   <ns1:Body>
      <ns2:GetFolder>
         <ns2:FolderShape>
            <ns0:BaseShape>Default</ns0:BaseShape>
         </ns2:FolderShape>
         <ns2:FolderIds>
            <ns0:DistinguishedFolderId Id="inbox"/>
         </ns2:FolderIds>
      </ns2:GetFolder>
   </ns1:Body>
</SOAP-ENV:Envelope>

Result:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInvalidRequest</faultcode>
            <faultstring xml:lang="de-AT">The request is invalid.</faultstring>
            <detail>
                <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInvalidRequest</e:ResponseCode>
                <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request is invalid.</e:Message>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

The only difference between my request and the MS developer documentation are the namespace prefixes.

Any ideas on what's wrong with that request?


Solution

  • I tested a lot and found out that somehow Exchange does not like the <ns0:DistinguishedFolderId Id="inbox"/> element. If I remove it, I won't get an invalid request response, but that the folderIds are missing.

    It seems like SUDS is not really maintained any more and I even tried to use suds jurko, but I got similar issues. So a lot of work, and not really a useable way to use EWS SOAP with python.

    It seems like I have to switch back for that prog to Groovy and Java.