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

TypeError: can't compare offset-naive and offset-aware datetimes in token expiration logic (v2.6.2)

Open alexandrosspyrou opened this issue 5 months ago • 2 comments

Upgrading from version 2.5.5 to 2.6.2 of office365-rest-python-client causes a TypeError during authentication when using certificate-based access tokens. The error occurs due to a comparison between a timezone-naive and a timezone-aware datetime object in the _authenticate method.

To Reproduce Steps to reproduce the behavior:

Use certificate-based authentication with ConfidentialClientApplication and ClientContext.with_access_token(...). Attempt to upload a file to SharePoint using ctx.execute_query(). Observe the following traceback: TypeError: can't compare offset-naive and offset-aware datetimes File "...\authentication_context.py", line 186, in _authenticate if self._cached_token is None or request_time > self._token_expires: Expected behavior Datetime comparisons should be consistent — either both timezone-aware or both naive — to avoid runtime errors.

Environment:

Python 3.11 office365-rest-python-client 2.6.2 OS: Windows 11 Additional context This issue did not occur in version 2.6.1. It appears that internal changes in how token expiration is handled introduced stricter datetime comparisons.

alexandrosspyrou avatar Jun 26 '25 08:06 alexandrosspyrou