Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

PR Summary

This PR fixes the datetime deprecation warnings that can be viewed in the CI logs:

test/sasl/test_msk.py::test_aws_msk_iam_client_temporary_credentials
  /home/runner/work/kafka-python/kafka-python/test/sasl/test_msk.py:13: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    now = datetime.datetime.utcfromtimestamp(1629321911)

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@dpkp
Copy link
Owner

dpkp commented Apr 16, 2025

Can we modify to keep support for python2.7 ?

@emmanuel-ferdman
Copy link
Contributor Author

@dpkp If Python2.7 support is required, I think we could go with something like:

import sys

if sys.version_info >= (3, 3):
    # Use timezone-aware datetime for Python 3.3+
    now = datetime.datetime.fromtimestamp(1629321911, datetime.timezone.utc)
else:
    # Fallback to utcfromtimestamp for Python 2.7
    now = datetime.datetime.utcfromtimestamp(1629321911)

Not the most elegant solution, but it should get the job done while supporting Python 2.7 and future Python versions. What do you think?

@dpkp
Copy link
Owner

dpkp commented Apr 16, 2025

That's great, thanks!

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@dpkp dpkp merged commit e2c3b80 into dpkp:master Apr 16, 2025
18 checks passed
@dpkp
Copy link
Owner

dpkp commented Apr 16, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants