From 4ded3bb0129f9826c59abb05c02637c2190e1ecc 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..eba0a069 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.UTC).utctimetuple()), "exp": calendar.timegm( - (datetime.datetime.utcnow() + self.ttl).utctimetuple() + (datetime.datetime.now(datetime.UTC) + self.ttl).utctimetuple() ), } )