aws / efs-utils

Utilities for Amazon Elastic File System (EFS)
MIT License
301 stars 192 forks source link

Fix utcnow() deprecation warning #197

Closed major closed 9 months ago

major commented 9 months ago

Issue #, if available:

187

Description of changes:

Replaces datetime.utcnow() with datetime.now(timezone.utc) to avoid deprecation warnings in Python 3.12.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Agreed! ✅

DaveWK commented 9 months ago

Hi - just also discovered this issue with my setup as well.

I am running w/ python 3.12.1 and the amazon-efs-mount-watchdog.service (which runs the watchdog python) was giving me back the error: TypeError: can't subtract offset-naive and offset-aware datetimes

On line 1578 it parses the cert's date with strptime which doesn't have a timezone, causing it to barf, so I changed it to: certificate_creation_time = datetime.strptime(state["certificateCreationTime"],CERT_DATETIME_FORMAT).replace(tzinfo=timezone.utc)

and now it works