Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

ctx.execute_batch() throws TypeError: can't compare offset-naive and offset-aware datetimes

Open matschundbrei opened this issue 7 months ago • 1 comments

After upgrading via pip from 2.6.1 to 2.6.2 we receive the error from the title (details below) on the start of

ctx = ClientContext(url).with_access_token(spTokenService.getAccessTokenResponse)
[...]
ctx.execute_batch()
self.ctx.execute_batch()
    ~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/office365/sharepoint/client_context.py", line 200, in execute_batch
    batch_request.execute_query(qry)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/client_request.py", line 36, in execute_query
    request = self.build_request(query)
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/odata/v3/batch_request.py", line 32, in build_request
    request.data = self._prepare_payload(query)
                   ~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/odata/v3/batch_request.py", line 77, in _prepare_payload
    request = qry.build_request()
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/queries/client_query.py", line 35, in build_request
    return self.context.build_request(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/client_runtime_context.py", line 40, in build_request
    self.pending_request().beforeExecute.notify(request)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/types/event_handler.py", line 41, in notify
    listener(*args, **kwargs)
    ~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/office3[65](https://code.stroeer.de/bi/s4r-bice-sharepoint-s3-sync/-/jobs/1135972#L65)/sharepoint/client_context.py", line 272, in _authenticate_request
    self.authentication_context.authenticate_request(request)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/auth/authentication_context.py", line 275, in authenticate_request
    self._authenticate(request)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/office365/runtime/auth/authentication_context.py", line 186, in _authenticate
    if self._cached_token is None or request_time > self._token_expires:
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

Note: we're pulling the module via pip inside a docker-image FROM python:3-alpine

downgrading back to 2.6.1 fixes the issue.

matschundbrei avatar May 20 '25 13:05 matschundbrei

Greetings!

Thank you for catching and reporting this issue. It looks like this PR is addressing it.

vgrem avatar May 20 '25 18:05 vgrem