Skip to content

Commit 1669e50

Browse files
committed
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.
1 parent 7380485 commit 1669e50

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

livekit-api/livekit/api/access_token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def to_jwt(self) -> str:
154154
{
155155
"sub": self.identity,
156156
"iss": self.api_key,
157-
"nbf": calendar.timegm(datetime.datetime.utcnow().utctimetuple()),
157+
"nbf": calendar.timegm(datetime.datetime.now(datetime.datetime.UTC).utctimetuple()),
158158
"exp": calendar.timegm(
159-
(datetime.datetime.utcnow() + self.ttl).utctimetuple()
159+
(datetime.datetime.now(datetime.datetime.UTC) + self.ttl).utctimetuple()
160160
),
161161
}
162162
)

0 commit comments

Comments
 (0)