Skip to content

Commit

Permalink
Resolve deprecation warning related to using datetime.utcnow in py3.12
Browse files Browse the repository at this point in the history
Starting from python 3.12.0, we started seeing some deprecation warning related to use of `datetime.datetime.utcnow`:

```
/Users/.../lib/python3.12/site-packages/fastapi_jwt/jwt.py:135: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
now = datetime.utcnow()
```

This PR should provide the same level of functionality without firing a deprecation warning, by implementing the suggested change.
  • Loading branch information
brouberol committed Nov 1, 2023
1 parent 41ca572 commit 71e4bca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fastapi_jwt/jwt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
from typing import Any, Dict, Optional, Set
from uuid import uuid4

Expand Down Expand Up @@ -132,7 +132,7 @@ def _generate_payload(
unique_identifier: str,
token_type: str,
) -> Dict[str, Any]:
now = datetime.utcnow()
now = datetime.now(UTC)

return {
"subject": subject.copy(), # main subject
Expand Down

0 comments on commit 71e4bca

Please sign in to comment.