Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replace deprecated datetime.utcnow() in websocket_api (Python 3.12+) - #187

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

Replace deprecated datetime.utcnow() in websocket_api (Python 3.12+)#187
MBK-fr wants to merge 1 commit into
samugit83:masterfrom
MBK-fr:fix/py312-utcnow-deprecation

Conversation

@MBK-fr

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

Copy link
Copy Markdown

What

agentic/websocket_api.py uses datetime.utcnow() in five places (connection connected_at/last_ping and JSON message timestamp fields).

Why

utcnow() is deprecated since Python 3.12 and scheduled for removal, so it emits a DeprecationWarning at runtime.

Fix

Replaced with datetime.now(timezone.utc).replace(tzinfo=None), which produces the exact same naive UTC datetime. The stored timestamps and the .isoformat() strings sent over the websocket are therefore byte for byte identical (no +00:00 suffix is introduced). timezone is added to the existing from datetime import datetime import.

The already-guarded site in scanners/github_secret_hunt/github_secret_hunt.py (which intentionally selects utcnow() vs now(timezone.utc) based on tzinfo) is left untouched. Compiles clean.

agentic/websocket_api.py uses datetime.utcnow() in five places (connection
timestamps and JSON message timestamps). utcnow() is deprecated since Python
3.12 and scheduled for removal (DeprecationWarning at runtime).

Replaced with datetime.now(timezone.utc).replace(tzinfo=None), which yields
the exact same naive UTC value, so the stored timestamps and the
.isoformat() strings sent over the websocket are byte-for-byte identical.
timezone is added to the existing datetime import.
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