Skip to content

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

@matschundbrei

Description

@matschundbrei

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions