Forums

New to Python and stuck on likely something simple

hey guys,

im new to python and i am working on creating an automated script to run at certain times of the day. basically i am passing a unix timestamp to a query. the script works 100% of the time when i run it from pycharm on my desktop or when i run it from the pythonanywhere editor, or in the bash consoles in pythonanywhere. however, when i set the script to run as an automated task, it throws an error and does not run at all. this is the code i am using and this is the error i get: if someone could help me correct my mistake in order to automate my tasks, it would be extremely appreciated!!

this is my import statement used:

from datetime import datetime  
timestamp_today = datetime.today().timestamp()

and the error i get:

File "/home/somesite/dir/fetchstuff.py", line 84, in fetch
timestamp_today = datetime.today().timestamp() AttributeError: 'datetime.datetime' object has no attribute 'timestamp'
2017-12-19 02:31:18 -- Completed task, took 33.00 seconds, return code was 1.

[edited by admin: formatting]

hi there- if you look further up in your traceback, you should be able to see which version of python you are using (eg: is it python2.7, is it python3.6, is it a virtualenv python etc)

are you sure you are using the same version of python in your bash console/editor vs your automated task?

Once you have figured out which python you need, take a look at this help page for how to specify it for your tasks.