Retrieve Exchange Calendar event with Python & Suds
<p>I'm trying to retrieve Exchange calendar events in Python using the suds library.</p>

<p>I'm able to read FreeBusyResponse data, but I'm not successfull in retrieving the actual calendar event.</p>

<p>The soap requests seems fine:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;SOAP-ENV:Envelope
xmlns:ns0="http://schemas.microsoft.com/exchange/services/2006/types"     
xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messages"     
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
&lt;SOAP-ENV:Header&gt;
      &lt;t:RequestServerVersion Version="Exchange2010_SP1"/&gt;
   &lt;/SOAP-ENV:Header&gt;
   &lt;SOAP-ENV:Body&gt;
      &lt;ns1:FindItem Traversal="Shallow"&gt;
         &lt;ns1:ItemShape&gt;
            &lt;ns0:BaseShape&gt;Default&lt;/ns0:BaseShape&gt;
         &lt;/ns1:ItemShape&gt;
         &lt;ns1:CalendarView xsi:type="ns0:CalendarViewType" StartDate="2016-10-17T14:10:41.620151+01:00" EndDate="2016-10-17T14:10:41.620176+01:00"/&gt;
         &lt;ns1:ParentFolderIds&gt;
            &lt;ns0:DistinguishedFolderId xsi:type="ns0:DistinguishedFolderIdType" Id="calendar"&gt;
               &lt;ns0:Mailbox&gt;
                  &lt;ns0:EmailAddress&gt;dries@myhost.be&lt;/ns0:EmailAddress&gt;
               &lt;/ns0:Mailbox&gt;
            &lt;/ns0:DistinguishedFolderId&gt;
         &lt;/ns1:ParentFolderIds&gt;
      &lt;/ns1:FindItem&gt;
   &lt;/SOAP-ENV:Body&gt;
&lt;/SOAP-ENV:Envelope&gt;
</code></pre>

<p>Relvant part in the code:</p>

<pre><code>find_item_request = client.factory.create('FindItemType')
shape_types = client.factory.create('ns1:DefaultShapeNamesType')
shape_type = client.factory.create('ns1:ItemResponseShapeType')
shape_type.BaseShape = 'Default'
find_item_request.ItemShape = shape_type
find_item_request._Traversal = 'Shallow'

mailbox = Element('ns1:Mailbox')
emailaddress = Element('ns1:EmailAddress').setText('dries@myhost.be')
mailbox.append(emailaddress)

folder_id_type = client.factory.create('ns1:DistinguishedFolderId')
folder_id_type.Mailbox = mailbox
folder_id_type._Id = 'calendar'

folder_ids = client.factory.create('ns1:NonEmptyArrayOfBaseFolderIdsType')
folder_ids.DistinguishedFolderId = folder_id_type
find_item_request.ParentFolderIds = folder_ids

calendar_view = client.factory.create('ns1:CalendarViewType')
calendar_view._StartDate = start
calendar_view._EndDate = end
find_item_request.CalendarView = calendar_view

client.service.FindItem.method.soap.input.body.wrapped = False

try:
  find_item_response = client.service.FindItem(find_item_request)
except WebFault as e:
  raise e
msg = result.FindItemResponseMessage
</code></pre>

<p>Should I use something else than a CalendarView?</p>

<p>I've found the following solution:</p>

<pre><code>import time
import datetime
import pytz
from suds.client import WebFault
from suds.client import Client
from suds.sax.element import Element
from suds.transport.http import HttpTransport
from suds.sudsobject import asdict

&lt; auth and transport comes here &gt;

# Todo: fix timezones displayed in suds output.
start = datetime.datetime.now(pytz.timezone('Europe/Brussels')).isoformat()
end = datetime.datetime.now(pytz.timezone('Europe/Brussels')).isoformat()

fi = client.factory.create('FindItem')
fi.ItemShape.BaseShape = 'AllProperties'
fi.ParentFolderIds.DistinguishedFolderId = client.factory.create('t:DistinguishedFolderIdType')
fi.ParentFolderIds.DistinguishedFolderId._Id = 'calendar'
fi._Traversal = 'Shallow'

calendar_view = client.factory.create('CalendarView')
calendar_view._StartDate = start
calendar_view._EndDate = end
fi.CalendarView = calendar_view

#client.service.FindItem.method.soap.input.body.wrapped = False

try:
  response = client.service.FindItem(**asdict(fi))
  print response
except WebFault as e:
  raise e
</code></pre>

python ews exchangewebservices suds