【问题标题】:Retrieve Exchange Calendar event with Python & Suds使用 Python 和 Suds 检索 Exchange 日历事件
【发布时间】:2016-10-17 12:33:43
【问题描述】:

我正在尝试使用 suds 库在 Python 中检索 Exchange 日历事件。

我能够读取 FreeBusyResponse 数据,但我无法成功检索实际的日历事件。

soap 请求看起来不错:

<?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>dries@myhost.be</ns0:EmailAddress>
               </ns0:Mailbox>
            </ns0:DistinguishedFolderId>
         </ns1:ParentFolderIds>
      </ns1:FindItem>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

代码中的相关部分:

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

我应该使用 CalendarView 以外的东西吗?

【问题讨论】:

    标签: python exchangewebservices suds


    【解决方案1】:

    我找到了以下解决方案:

    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
    

    【讨论】:

      猜你喜欢
      • 2015-03-18
      • 2011-01-16
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多