I have an arcpy Python script that downloads an Excel spreadsheet and then copies one of the sheets from the document to a table in a geodatabase. I need this script to run automatically every night, unattended, and so have it configured from the Windows Task Scheduler.
The script runs fine when run directly from the IDE.
When run from the Task Scheduler (as the same user) it can see the Excel file, but it cannot see any of the sheets within the file. Ie...
os.path.exists(filepath)
returns Truearcpy.Exists(filepath)
returns Truearcpy.Exists(os.path.join(filepath, sheetname))
returns False when run from Task Scheduler (but returns True when run from IDE as the same user)arcpy.ListTables()
returns [ ] (empty list) when run from Task Scheduler (but returns a list of all the sheets when run from IDE as the same user)
The same problem occurs when run from the Task Scheduler whether it is configured to run only when user is logged in or run whether user is logged in or not.
Why can my script read the contents of the Excel file when run interactively, but not when run from the Task Scheduler?
I'm confident that it is not a permissions issue, because the script reads the same file just fine when run from the IDE as the same user for which it is run from the Task Scheduler.
Some Things I've Tried:
I have tried the solution to many posted problems that appear similar. Ie to create the following directories:
C:\Windows\System32\config\systemprofile\Desktop C:\Windows\SysWOW64\config\systemprofile\Desktop
However, I believe that this is only for opening an Excel file in Excel itself. It certainly did not resolve the problem for me when trying to read an Excel file with arcpy.
I also tried the solution for the question at: https://superuser.com/questions/622507/windows-task-scheduler-wont-run-file-on-non-system-drive
Ie, to give explicit permissions for the user to the file's directory, and not just relying on the group permissions. But this did not help either.
arcpy.env.workspace = filepath
. It works fine when run interactively from the IDE, as it lists all of the sheets in the spreadsheet then.