ecederstrand / exchangelib

Python client for Microsoft Exchange Web Services (EWS)
BSD 2-Clause "Simplified" License
1.18k stars 248 forks source link

Failed to update the end time of the meeting #762

Closed bigthing33 closed 4 years ago

bigthing33 commented 4 years ago

demo

def updateEvent(accountRoom,id):
    from exchangelib.items import SEND_MEETING_INVITATIONS_AND_CANCELLATIONS_CHOICES, SEND_ONLY_TO_ALL
    event = accountRoom.calendar.get(id=id)
    print('old end time',event.end)
    event.end=event.end
    event.save(update_fields=['end'], send_meeting_invitations=SEND_ONLY_TO_ALL)
    event = accountRoom.calendar.get(id=id)
    print('update end time',event.end)

error log

old end time 2020-05-30 12:30:00+00:00
/Library/Python/3.7/site-packages/urllib3/connectionpool.py:986: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.66.177'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
Traceback (most recent call last):
  File "list-event-demo.py", line 120, in <module>
    updateEvent(roomAccount,'AAMkAGEyZGMwMDkwLTBjNjctNGJlZi1hOTBlLTM0MjBlNzYzMWI2MQFRAAgI2AQsZXKAAEYAAAAAkmLfaidbM0yTyHgkoY0vjgcAvnfgpUJDY06wWVCn/u6UyAAAAAABDQAAvnfgpUJDY06wWVCn/u6UyAAACHV4VgAAEA==')
  File "list-event-demo.py", line 101, in updateEvent
    event.save(update_fields=['end'], send_meeting_invitations=SEND_ONLY_TO_ALL)
  File "/Library/Python/3.7/site-packages/exchangelib/items/item.py", line 100, in save
    send_meeting_invitations=send_meeting_invitations
  File "/Library/Python/3.7/site-packages/exchangelib/util.py", line 39, in wrapper
    return f(self, *args, **kwargs)
  File "/Library/Python/3.7/site-packages/exchangelib/items/item.py", line 183, in _update
    expect_result=message_disposition != SEND_AND_SAVE_COPY,
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 66, in get
    res = list(self.call(**kwargs))
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 540, in _pool_requests
    for elem in self._get_elements(payload=payload_func(chunk, **kwargs)):
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 403, in _get_elements_in_response
    container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 362, in _get_element_container
    raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)
exchangelib.errors.ErrorInvalidPropertySet: Set action is invalid for property. (field: FieldURI(field_uri='calendar:EndTimeZone'))

Am I writing it wrong? please help me. Thank you.

ecederstrand commented 4 years ago

The EndTimeZone field is supposedly supported from Exchange 2010 and forward. Which Exchange version is this? roomAccount.version will print the exact version.

bigthing33 commented 4 years ago

Thank you for your reply. Which Exchange version is this?>>>>>>> Exchange version: Build=15.1.1979.3, API=Exchange2016, Fullname=Microsoft Exchange Server 2016

ecederstrand commented 4 years ago

That's weird. I cannot reproduce, using the exact same Exchange version.

Can you enable debug logging (see https://github.com/ecederstrand/exchangelib#troubleshooting) and post the XML request and XML response that triggers this error?

bigthing33 commented 4 years ago

Debug Log

Request headers: {'User-Agent': 'exchangelib/3.2.0 (python-requests/2.23.0)', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'Keep-Alive', 'Content-Type': 'text/xml; charset=utf-8', 'X-AnchorMailbox': 'meeting_room@syncdemo.com', 'Cookie': 'X-BackEndCookie=S-1-5-21-824428130-1610771284-2106603043-1160=u56Lnp2ejJqByMnGnM6ZncbSx52ZydLLysvO0sfMzM7SxpvNnp7JnMmZysnJgYHNz83P0s/I0s/Nq8/Jxc7Ixc/GgYyGkZybmpKQ0ZyQkoHP&meeting_room@syncdemo.com=u56Lnp2ejJqByMnGnM6ZncbSx52ZydLLysvO0sfMzM7SxpvNnp7JnMmZysnJgYHNz83P0s/I0s/Nq8/Jxc7Ixc/GgYyGkZybmpKQ0ZyQkoHP; exchangecookie=d8cf1058cc8141df9bbfb55d66741b0d', 'Content-Length': '1382'}
Response headers: {'Cache-Control': 'private', 'Transfer-Encoding': 'chunked', 'Content-Type': 'text/xml; charset=utf-8', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Server': 'Microsoft-IIS/10.0', 'request-id': 'c4345d9c-43b9-4d4f-8fd5-2df6850ef6be', 'X-CalculatedBETarget': 'win-t0dm0juemh9.syncdemo.com', 'X-DiagInfo': 'WIN-T0DM0JUEMH9', 'X-BEServer': 'WIN-T0DM0JUEMH9', 'X-AspNet-Version': '4.0.30319', 'Set-Cookie': 'exchangecookie=d8cf1058cc8141df9bbfb55d66741b0d; path=/, X-BackEndCookie=S-1-5-21-824428130-1610771284-2106603043-1160=u56Lnp2ejJqByMnGnM6ZncbSx52ZydLLysvO0sfMzM7SxpvNnp7JnMmZysnJgYHNz83P0s/I0s/Nq8/Jxc7Ixc/GgYyGkZybmpKQ0ZyQkoHP&meeting_room@syncdemo.com=u56Lnp2ejJqByMnGnM6ZncbSx52ZydLLysvO0sfMzM7SxpvNnp7JnMmZysnJgYHNz83P0s/I0s/Nq8/Jxc7Ixc/GgYyGkZybmpKQ0ZyQkoHP; expires=Thu, 02-Jul-2020 06:17:09 GMT; path=/EWS; secure; HttpOnly', 'X-Powered-By': 'ASP.NET', 'X-FEServer': 'WIN-T0DM0JUEMH9', 'Date': 'Tue, 02 Jun 2020 06:17:09 GMT'}
Request data: <?xml version='1.0' encoding='utf-8'?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <s:Header>
    <t:RequestServerVersion Version="Exchange2016"/>
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        <t:PrimarySmtpAddress>meeting_room@syncdemo.com</t:PrimarySmtpAddress>
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="China Standard Time"/>
    </t:TimeZoneContext>
  </s:Header>
  <s:Body>
    <m:UpdateItem ConflictResolution="AutoResolve" MessageDisposition="SaveOnly" SendMeetingInvitationsOrCancellations="SendOnlyToAll" SuppressReadReceipts="true">
      <m:ItemChanges>
        <t:ItemChange>
          <t:ItemId Id="AAMkAGEyZGMwMDkwLTBjNjctNGJlZi1hOTBlLTM0MjBlNzYzMWI2MQFRAAgI2AgaOYNAAEYAAAAAkmLfaidbM0yTyHgkoY0vjgcAvnfgpUJDY06wWVCn/u6UyAAAAAABDQAAvnfgpUJDY06wWVCn/u6UyAAACHV4VgAAEA==" ChangeKey="DwAAABYAAAC+d+ClQkNjTrBZUKf+7pTIAAAKjJdz"/>
          <t:Updates>
            <t:SetItemField>
              <t:FieldURI FieldURI="calendar:End"/>
              <t:CalendarItem>
                <t:End>2020-06-04T20:30:00+08:00</t:End>
              </t:CalendarItem>
            </t:SetItemField>
            <t:SetItemField>
              <t:FieldURI FieldURI="calendar:EndTimeZone"/>
              <t:CalendarItem>
                <t:EndTimeZone Id="China Standard Time" Name=""/>
              </t:CalendarItem>
            </t:SetItemField>
          </t:Updates>
        </t:ItemChange>
      </m:ItemChanges>
    </m:UpdateItem>
  </s:Body>
</s:Envelope>

Response data: <?xml version='1.0' encoding='utf-8'?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo
    xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="1" MajorBuildNumber="1979" MinorBuildNumber="3" Version="V2017_07_11"/>
  </s:Header>
  <s:Body
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:UpdateItemResponse
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:UpdateItemResponseMessage ResponseClass="Error">
          <m:MessageText>Set action is invalid for property.</m:MessageText>
          <m:ResponseCode>ErrorInvalidPropertySet</m:ResponseCode>
          <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
          <m:MessageXml>
            <t:FieldURI FieldURI="calendar:EndTimeZone"/>
          </m:MessageXml>
          <m:Items/>
        </m:UpdateItemResponseMessage>
      </m:ResponseMessages>
    </m:UpdateItemResponse>
  </s:Body>
</s:Envelope>

DEBUG:exchangelib.util:No retry: wrong status code 200
DEBUG:exchangelib.util:Session 26168 thread 4700618176: Useful response from https://192.168.66.177/EWS/Exchange.asmx
DEBUG:exchangelib.protocol:Server 192.168.66.177: Releasing session 26168
DEBUG:exchangelib.version:API version "Exchange2016" worked but server reports version "V2017_07_11". Using "Exchange2016"
Traceback (most recent call last):
  File "update-event-demo.py", line 80, in <module>
    updateEvent(roomAccount,'AAMkAGEyZGMwMDkwLTBjNjctNGJlZi1hOTBlLTM0MjBlNzYzMWI2MQFRAAgI2AgaOYNAAEYAAAAAkmLfaidbM0yTyHgkoY0vjgcAvnfgpUJDY06wWVCn/u6UyAAAAAABDQAAvnfgpUJDY06wWVCn/u6UyAAACHV4VgAAEA==')
  File "update-event-demo.py", line 72, in updateEvent
    event.save(update_fields=['end'], send_meeting_invitations=SEND_ONLY_TO_ALL)
  File "/Library/Python/3.7/site-packages/exchangelib/items/item.py", line 100, in save
    send_meeting_invitations=send_meeting_invitations
  File "/Library/Python/3.7/site-packages/exchangelib/util.py", line 39, in wrapper
    return f(self, *args, **kwargs)
  File "/Library/Python/3.7/site-packages/exchangelib/items/item.py", line 183, in _update
    expect_result=message_disposition != SEND_AND_SAVE_COPY,
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 66, in get
    res = list(self.call(**kwargs))
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 540, in _pool_requests
    for elem in self._get_elements(payload=payload_func(chunk, **kwargs)):
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 403, in _get_elements_in_response
    container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)
  File "/Library/Python/3.7/site-packages/exchangelib/services/common.py", line 362, in _get_element_container
    raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)
exchangelib.errors.ErrorInvalidPropertySet: Set action is invalid for property. (field: FieldURI(field_uri='calendar:EndTimeZone'))
DEBUG:exchangelib.protocol:Server 192.168.66.177: Closing sessions
ecederstrand commented 4 years ago

It's a bit hard to read from the debug log, but it this calendar item a meeting that the user was invited to? If so, then I believe only the user who created the created the meeting invitation can change it.

bigthing33 commented 4 years ago
bigthing33 commented 4 years ago
ecederstrand commented 4 years ago

I don't think it makes a difference that the Name attribute is there, but you can try the referenced commit.

Can you try creating a new calendar item using the connecting user, and then editing it using the same user? Then we can see if it's a general problem, or a problem with just this one calendar item. Something like:

from exchangelib import Account, CalendarItem, UTC_NOW
a = Account(...)
i = CalendarItem(folder=a.calendar, subject='test', start=UTC_NOW(), end=UTC_NOW()).save()
i.save(update_fields=['end'])
bigthing33 commented 4 years ago

Here are my steps to reproduce

def getFirstMeeting(accountRoom): start = accountRoom.default_timezone.localize(EWSDateTime.now()) end = start + timedelta(hours=24*10) events = accountRoom.calendar.view(start=start,end=end).all() print('events',events) resutlEvents=[] for event in events: resutlEvents.append(event) resutlEvents=resutlEvents return resutlEvents[0]

def updateMeetingEndTime(accountRoom,event): from exchangelib.items import SEND_MEETING_INVITATIONS_AND_CANCELLATIONS_CHOICES, SEND_ONLY_TO_ALL now = account.default_timezone.localize(EWSDateTime.now()) end = now + timedelta(hours=0.5) event.end = end event.save(update_fields=['end'], send_meeting_invitations=SEND_ONLY_TO_ALL) event = accountRoom.calendar.get(id=event.id)

create account use smtpAddress of a room resource

roomAccount=createAccount('meeting_room@syncdemo.com') firstMeeting=getFirstMeeting(roomAccount)

try to update meeting

updateMeetingEndTime(roomAccount,firstMeeting)



### Simply put:
- The primary_smtp_address I used when creating the meeting is: Allen@syncdemo.com
- The primary_smtp_address I used to find and update the end time of the meeting is: meeting_room@syncdemo.com
ecederstrand commented 4 years ago

Ok. That makes sense.

I'm pretty sure that this is not supported in Exchange. If you want to change a meeting with attendees and/or rooms, only the organizer can do that. So you either log in as this user, or at least impersonate as this user, when making changes to the item.

The error message from Exchange could be more helpful than just ErrorInvalidPropertySet. I guess we could compare the connecting account with the organizer field and throw a more helpful error message.

bigthing33 commented 4 years ago

Yes, you are right.

You are so cool, thank you very much.