flet icon indicating copy to clipboard operation
flet copied to clipboard

DeprecationWarning -> time.datetime.utcnow()

Open rasool-mrr opened this issue 2 years ago • 1 comments

I'm using python 3.12 and the latest version of flet and I keep getting this error when I use hot reload

The hot reload command that I'm using is:

flet -r -w -p 8080

And this is the DeprecationWarning:

C:\Users\Russell\Desktop\app\current\.venv\Lib\site-packages\flet_core\page.py:292: DeprecationWarning: date
time.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).

I manage to fix it by replacing line 292 with this code:

from datetime import datetime, timedelta, UTC

datetime.now(UTC)

also this line get the same DeprecationWarning:

C:\Users\Russell\Desktop\app\current\.venv\Lib\site-packages\flet\fastapi\flet_app_manager.py:124: 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).
  if page.expires_at and datetime.utcnow() > page.expires_at:

I think this would be a good solution:

import sys
from datetime import datetime, UTC

python_version = int(sys.version.split(" ")[0].split(".")[1])

print(python_version)

if python_version > 11:
    print("True")
    print(datetime.now(UTC))
else:
    print(datetime.utcnow())
    ```

rasool-mrr avatar Mar 10 '24 09:03 rasool-mrr

It has been fixed by this commit: https://github.com/flet-dev/flet/commit/45bea5d008d224b1f83a8d0dc437dce9443012b8 Will be present in the upcoming version.

ndonkoHenri avatar Mar 10 '24 11:03 ndonkoHenri