1

I have a python 3 script that relies on (among other things) selenium, bs4, smtplib, and xlsxwriter. The script scrapes a website, saves a large chunk of data to an Excel file, and then emails me smaller chunks of data that are of particular interest. I have run the script numerous times and it works fine (i.e., it writes the excel file and emails me).

Recently, I used Task Scheduler on Windows 10 to set this script to run every 24 hours. The program apparently runs (and is recorded as successful by Task Scheduler). The problem is the when Task Scheduler executes the program I only receive the email with smaller chunks of data. The Excel file is not written.

Under Task Scheduler, I put the following in the Program/Script box: C:\path\to\python\python.exe. Under Arguments, I put: C:\path\to\script.py.

Note, per a previous SO question, I tried putting cmd under Program/Script and then C:\path\to\python\python.exe C:\path\to\script.py as the arguments. The program didn't run at all with the latter cmd setup.

Not sure if relevant, but I added c:\path\to\python\python36-32\ and c:\path\to\scriptfolder\ to my system variables path. I put #!python3 at the top of my scripts. Thanks.

vintagedeek
  • 161
  • 2
  • 10
  • Do you have a log file to post here? If not, you should use one. It can have logging messages like whether or not it was able to find a path, open a file, etc. – C S May 30 '17 at 16:15
  • sorry, I am newb. Are you referring to the History of the Task Event? If so, mine reads: "Task Scheduler successfully finished "{abcef-geda-5555-4444-2701080b34bf}" instance of the "\Microsoft\Windows\TaskScheduler\sw_dad.py" task for user "DESKTOP-xxxx\name" Event ID is 102, OpCode is (2). I see other details in the History section. The first says "Task triggered on scheduler. 2nd says 'created task process.' 3rd says 'task started.' 4th says 'action started.' 5th says 'action completed.' 6th says 'task completed.' – vintagedeek May 30 '17 at 16:30

1 Answers1

2

Solved. My script wrote an Excel file to the current working directory when run in PowerShell. When run through Task Scheduler, the file was written to the path specified in the Start In (Optional) box. I had the path to python.exe there per StackOverflow suggestions. So the file was written in c:\python\python36-32. I changed the Start in (optional) box to the preferred path for saving the Excel file and it worked.

vintagedeek
  • 161
  • 2
  • 10