I have a .py script that works when I run it in the console but seems to fail when I schedule it as an automatic task. The script uses the urllib.request (I made sure to set the Hashbang to run Python 3.6 which supports that package #!/usr/bin/python3.6) to hit and download a file from a specific URL.. Again no problems when I run it manually, but when its run as a scheduled task I get this error:
Traceback (most recent call last):
File "/home/laiAdmin/Scripts/FullAutoSubStats.py", line 32, in <module>
urllib.request.urlretrieve(URL, dlFileName)
File "/usr/lib/python3.6/urllib/request.py", line 258, in urlretrieve
tfp = open(filename, 'wb')
FileNotFoundError: [Errno 2] No such file or directory: '/home/laiAdmin/Data_Files/Downloads/FWdirect-Daily-Stats-Parser-autoDl-2018-05-08.json'
2018-05-08 16:48:11 -- Completed task, took 6.00 seconds, return code was 1.
The code snippet it is pointing to is the following (hiding the URL):
#Get timestamp and PWD
cwd = os.getcwd()
now = DT.datetime.utcnow()-DT.timedelta(hours=6)
todayStr = DT.datetime.strftime(now,"%Y-%m-%d")
nowStr = DT.datetime.strftime(now,"%m/%d/%Y %H:%M:%S")
#Request to download a new json file:
rootdir = cwd+'/Data_Files/Downloads/'
URL = "https://files.mailparser.io/d/*****"
#(hiding the full URL here for security purposes)
fn = "FWdirect-Daily-Stats-Parser-autoDl-"+todayStr+".json"
dlFileName = rootdir+fn
urllib.request.urlretrieve(URL, dlFileName)
The last line is where the traceback takes place. Please help me to understand why this runs when I hit run in the console, but fails when I schedule it as a task.