botocore icon indicating copy to clipboard operation
botocore copied to clipboard

Fix datetime deprecation warning

Open bubai2000 opened this issue 10 months ago • 5 comments

When running boto3 on Python 3.12 environment, there is a deprecation warning "DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC)". This PR tries to address this issue.

bubai2000 avatar Feb 03 '25 19:02 bubai2000

I've already opened a PR to address this: #3239.

The method used in this PR has been previously attempted, but had to be discarded because it made the datetime objects timezone-aware.

In addition, the datetime.UTC alias used in this PR is only available in Python 3.11 and higher, and would cause AttributeErrors in lower Python versions.

kurtmckee avatar Feb 26 '25 09:02 kurtmckee

Understandable. Can you please share a solution for this?

bubai2000 avatar Feb 26 '25 10:02 bubai2000

PR #3239 is the solution. Unfortunately, the maintainers of botocore have not reviewed and merged the PR yet.

You can suppress the warnings by configuring Python and/or pytest warnings. I recommend searching for "python suppress warnings" and "pytest suppress warnings", depending on your needs.

kurtmckee avatar Feb 26 '25 11:02 kurtmckee

Thanks a lot!

bubai2000 avatar Feb 26 '25 14:02 bubai2000

I'd appreciate this as well!

gordonkoehn avatar Mar 28 '25 15:03 gordonkoehn

Resolving in favor of https://github.com/boto/botocore/pull/3239. Thanks for the contribution though!

nateprewitt avatar Aug 01 '25 20:08 nateprewitt