From 658b4f50945f8465560953b1886e5bcb1fd69ac0 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Sun, 3 Nov 2024 16:36:58 +0100 Subject: [PATCH] update datetime.utcnow() to use UTC timezone-aware object datetime.utcnow() is being deprecated in Python 3.12 as it returns a naive datetime object without timezone information. Replace with datetime.now(UTC) to use an explicit timezone-aware object, preventing potential timezone ambiguity issues. In access_token.py, updated the token expiration calculation to use the recommended timezone-aware approach. --- livekit-api/livekit/api/access_token.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/livekit-api/livekit/api/access_token.py b/livekit-api/livekit/api/access_token.py index baa2b71e..b09626d7 100644 --- a/livekit-api/livekit/api/access_token.py +++ b/livekit-api/livekit/api/access_token.py @@ -154,9 +154,9 @@ def to_jwt(self) -> str: { "sub": self.identity, "iss": self.api_key, - "nbf": calendar.timegm(datetime.datetime.utcnow().utctimetuple()), + "nbf": calendar.timegm(datetime.datetime.now(datetime.timezone.utc).utctimetuple()), "exp": calendar.timegm( - (datetime.datetime.utcnow() + self.ttl).utctimetuple() + (datetime.datetime.now(datetime.timezone.utc) + self.ttl).utctimetuple() ), } )