Skip to content

Commit

Permalink
update datetime.utcnow() to use UTC timezone-aware object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lebaudantoine committed Nov 3, 2024
1 parent 7380485 commit 4ded3bb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
),
}
)
Expand Down

0 comments on commit 4ded3bb

Please sign in to comment.