2016-10-17 7 views
0

Я пытаюсь получить события календаря Exchange в Python, используя библиотеку suds.Получить событие календаря Exchange с помощью Python & Suds

Я могу прочитать данные FreeBusyResponse, но мне не удастся получить реальное событие календаря.

мыло запросов кажется отлично:

<?xml version="1.0" encoding="UTF-8"?> 
<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/"> 
<SOAP-ENV:Header> 
     <t:RequestServerVersion Version="Exchange2010_SP1"/> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <ns1:FindItem Traversal="Shallow"> 
     <ns1:ItemShape> 
      <ns0:BaseShape>Default</ns0:BaseShape> 
     </ns1:ItemShape> 
     <ns1:CalendarView xsi:type="ns0:CalendarViewType" StartDate="2016-10-17T14:10:41.620151+01:00" EndDate="2016-10-17T14:10:41.620176+01:00"/> 
     <ns1:ParentFolderIds> 
      <ns0:DistinguishedFolderId xsi:type="ns0:DistinguishedFolderIdType" Id="calendar"> 
       <ns0:Mailbox> 
        <ns0:EmailAddress>[email protected]</ns0:EmailAddress> 
       </ns0:Mailbox> 
      </ns0:DistinguishedFolderId> 
     </ns1:ParentFolderIds> 
     </ns1:FindItem> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

Relvant часть в коде:

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('[email protected]') 
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 

Должен ли я использовать что-то другое, чем CalendarView?

ответ

0

Я нашел следующее решение:

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 

< auth and transport comes here > 

# 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