pynetdicom not working correctly with Windows Task Scheduler

I am using a modified version of this pynetdicom script (the second example on this page) to download DICOM images to an office computer. Here is what the script does:

  1. Opens a connection with PACS
  2. Searches for DICOM images that match the current date for a given patient’s medical record number and accession number.
  3. If DICOM images are found that match the given criteria, then an SCP server connection is started to initiate the downloading of images to a folder on the local computer.

The script works when it is run using the Spyder IDE. I have created a scheduled task with Windows Task Scheduler and it works correctly if the script has first been run with the Spyder IDE and only if Spyder remains open and all variables have not been cleared.

However, if Spyder is closed or the Spyder kernel is restarted, then when the script is run through task scheduler, it will run correctly until it gets to the part where the SCP server calls the handle_store function that downloads images from PACS. The script does not call the handle_store function and the connection eventually times out.

I thought the solution would be changing the default working directory in Task Scheduler, but that did not work. Any ideas what is going on and how to fix this?

Answer

Okay, I did some more digging and found the source of the problem. In order to get images to download to my computer Python needs to be allowed through our corporate firewall. I had already allowed pythonw.exe through the firewall but not python.exe. Once both of these Python files were allowed through the firewall the script will run as expected when started with Windows Task Scheduler.