jertel / elastalert2

ElastAlert 2 is a continuation of the original yelp/elastalert project. Pull requests are appreciated!
https://elastalert2.readthedocs.org
Apache License 2.0
914 stars 287 forks source link

2.17.0 AttributeError: module 'datetime' has no attribute 'UTC' #1400

Closed buzzdeee closed 6 months ago

buzzdeee commented 6 months ago

Just installed elastalert2 on Ubuntu 22.04.4 LTS, with Python 3.10.12, and python-dateutil 2.9.0.post0, starting elastalert I see:

Traceback (most recent call last):
  File "/usr/local/bin/elastalert", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 1926, in main
    client.start()
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 1161, in start
    if next_run < datetime.datetime.now(tz=datetime.UTC):
AttributeError: module 'datetime' has no attribute 'UTC'

Traceback (most recent call last):
  File "/usr/local/bin/elastalert", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 1926, in main
    client.start()
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 1161, in start
    if next_run < datetime.datetime.now(tz=datetime.UTC):
AttributeError: module 'datetime' has no attribute 'UTC'

there are a few more places, but replacing all of the:

datetime.UTC

with

datetime.timezone.utc

made it properly start up for me.

jertel commented 6 months ago

The datetime.UTC alias was introduced after Python 3.10. Per the ElastAlert 2 docs, this project requires Python 3.12.

image

If you are unable to install or update Python on your host OS you can consider using the Docker image instead: https://elastalert2.readthedocs.io/en/latest/running_elastalert.html#as-a-docker-container

buzzdeee commented 6 months ago

thank you, I was updating from an older Ubuntu with older elastalert2 version to the versions mentioned above, didn't expect the python 3.12 requirement.