Skip to content

Replace deprecated datetime.utcnow() in the certificate builder (Python 3.12+) - #20

Open
MBK-fr wants to merge 1 commit into
zblurx:mainfrom
MBK-fr:fix/py312-utcnow-deprecation
Open

Replace deprecated datetime.utcnow() in the certificate builder (Python 3.12+)#20
MBK-fr wants to merge 1 commit into
zblurx:mainfrom
MBK-fr:fix/py312-utcnow-deprecation

Conversation

@MBK-fr

@MBK-fr MBK-fr commented Sep 10, 2026

Copy link
Copy Markdown

What

certsync/entry.py builds the self-signed certificate with datetime.datetime.utcnow() for not_valid_before and not_valid_after.

Why

utcnow() is deprecated since Python 3.12 and scheduled for removal (DeprecationWarning at runtime). Separately, cryptography now deprecates naive datetimes passed to not_valid_before/after.

Fix

Replaced with datetime.datetime.now(timezone.utc). The two calls still denote the same UTC instants (minus 1 day / plus 365 days), and passing timezone-aware datetimes is the recommended form for cryptography, so this also removes its naive-datetime warning. Compiles clean; two lines.

….12+)

The self-signed certificate builder uses datetime.datetime.utcnow() for
not_valid_before/not_valid_after. utcnow() is deprecated since Python 3.12
and scheduled for removal.

Replaced with datetime.datetime.now(timezone.utc). The values still denote
the same UTC instants, and passing timezone-aware datetimes to
cryptography's not_valid_before/after is the recommended form (it also
silences cryptography's own naive-datetime deprecation warning).
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.

1 participant