I have a Python script, which connects to a data feed in the early hours of each morning, downloads a JSON data file, then moves it from where it saved it to a dedicated folder.
When the script is run from the command line on the Linux Centos7 server, all works perfectly.  When run through Cron (either on schedule or a run now through the Plesk Cron screen) it errors out.  Having commented out the os.rename(startfile, sendfile) line the script runs perfectly in Cron.
I thought it was todo with permissions, but if I get the same script to open a text file in the eventual destination directory that I am trying to move the datafile to, write 'JSON file downloaded ok' and close the file - that runs perfectly under CRON, so I dont think it can be permissions.
I have run os.path.isfile(StartFile) on the datafile after downloaded (and got TRUE) and run os.path.isdir(EndFile) and got TRUE, so I know the paths are correct.  I have replaced os.rename with os.replace and the same thing happens.
When the script downloads it, it goes into the /root/ folder, as CRON runs as root. When the script exits with an error, the file is there and visible in /root/ and I can manually do mv file.gz to /path/to/folder/file.gz and it moves fine.
Just CRON is having some issue with the Python file movement commands - can anyone offer any advice, I just dont know where to check next!
Thanks to @kpie in the above comments, the answer (although I suppose it is a workaround rather than a solution) was to change the working directory with os.chdir(path) before downloading the file.
That way the file downloads into the folder I need it in, rather than downloading and then moving it.
Python script will not move a downloaded file when run as CRON