questrade_api icon indicating copy to clipboard operation
questrade_api copied to clipboard

Fix astimezone() and naive datetime

Open normcyr opened this issue 6 years ago • 1 comments

Issue

The current module only works for Python >= 3.6. You cannot call astimezone() on naive datetimes prior to Python 3.6.

`ValueError: astimezone() cannot be applied to a naive datetime`

Solution

Install pytz and tzlocal

pip install pytz tzlocal`

Get local timezone

import pytz
from tzlocal import get_localzone
tz = get_localzone()

Return datetime.now() with proper timezone

return tz.localize(datetime.now()).isoformat('T')

normcyr avatar Oct 27 '19 16:10 normcyr

The other workaround is obviously to require Python >= 3.6 for the module to work. I don't think this is practical.

On Debian at least, this would need user to be on Buster, or have manually installed Python >= 3.6.

normcyr avatar Oct 27 '19 17:10 normcyr