questrade_api
questrade_api copied to clipboard
Fix astimezone() and naive datetime
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')
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.