Obscure ExportToJPEG problem

04-25-2018 02:44 PM
New Contributor III

Here's a strange one ... would love to hear some feedback. I managed to fix the problem but I don't understand why this was a problem in the first place. I believe this has to do with how I was passing a directory string into the tool.

We have a relatively simple arcpy script that exports jpegs to a folder. The script runs on a Windows 2008 R2 server where we have both ArcGIS Server 10.3.1 installed along with ArcGIS 10.3.1 desktop. Since the latter was the last installed, the default Python IDLE is 32-bit.

When the script is run interactively in IDLE, it runs just fine with no errors. However, when run via Windows Task Scheduler, it throws the error "PageLayoutObject: Error in executing ExportToJPEG". I am 100% positive that it is running from the same user account when we run it either interactively in IDLE or via Task Scheduler, and that that user account has the correct privileges to the writeoff directory.

The offending code is this:

arcpy.mapping.ExportToJPEG(mxd, r"R:\GIS\Maps\Map_" + str(pageName) + ".jpg", resolution = 250)

But when I make a relatively minor change, it works fine:

writeoff_dir = "//somedirectory/GIS/Maps/"

arcpy.mapping.ExportToJPEG(mxd, writeoff_dir + "Map_" + str(pageName) + ".jpg", resolution = 250)

Again, I must emphasize that both code snippets work fine when run interactively in IDLE; it's only when the first snipped is run in Task Scheduler that it throws an error. I tried pointing Task Scheduler to a batch file that referenced either the 32-bit and 64-bit IDLE versions installed on the machine, but it didn't make a difference.

So two questions for the community:

1. Why doesn't the input appear to like the 'r' prefix for the path?

2. Why would these both run fine interactively in IDLE but the first code snippet bomb via Task Scheduler?

Thanks in advance. At a minimum, I hope my solution helps someone experiencing the same uninformative error.

0 Kudos
2 Replies
MVP Legendary Contributor

I wonder if it fails before it even gets to python since raw formatting is interpreted by python.  There is chatter about enclosing the full path to the script in double quotes and use the full path to the python executable when using scheduled paths and even shortcuts

0 Kudos
Occasional Contributor III

Hi Warren:

I know this question is old, I'm tracking a similar error and found this post.  I think your issue was a little different but thought I'd add a note since I was here:

If folder R:\GIS\Maps is a network/mapped drive, then it won't be accessible to task the account (even if it's the same account) when running as a background task.  Mapped drives are pretty much a "GUI only" thing unless your bat file/script creates it explicitly with the OS command.  The task scheduler runs as your defined account but doesn't load all the GUI aspects.  

So when you changed the path to the UNC style "//machine/GIS/Maps", it works b/c that path is resolvable.

Hope that helps someone else, back to tracking down my issue...