Error When Running a Python Script via Task Scheduler on Server

6660
13
Jump to solution
01-27-2014 03:31 PM
GeorgeHaskett
Occasional Contributor III
I previously built a model using Model Builder to process some data.  The model runs fine when manually started.  However, I would like to automate the process via the task scheduler on our GIS server.  The model in question is part of a longer python script.  The script routinely failed while trying to run the model.  I therefore rewrote the script and replaced the model with python code.  Again, it runs flawlessly when I manually start it, however it now snags on the arcpy.mapping.ExportReport() portion of the code.  Below is the error message I am receiving:

[INDENT]/n/nPYTHON ERRORS:
Traceback Info:
  File "C:\arcgisserver\gisData\services\eqMap\toolsNscripts\runEQAnalysis.py", line 402, in <module>
    arcpy.mapping.ExportReport(lyr,rlfPath,pdfPathTemp)

Error Info:
     <type 'exceptions.AttributeError'>: This functionality is not supported on server.
/n/n[/INDENT]

Why would it run flawlessly when manually triggered, but crash when triggered by the Task Scheduler?

The entire script is quite long, however below is the section its stopping at:

reportFolder = "C:/inetpub/wwwroot/flexviewers/_supportDocs/reports/" pdfPathTemp = reportFolder+"earthquakeReportTemp.pdf" rlfPath = "C:/arcgisserver/gisData/services/eqMap/toolsNscripts/agentReport.rlf" eq = policyList[0] whereClause = "EPICENTER = '"+eq+"'" lyr.definitionQuery = whereClause  arcpy.mapping.ExportReport(lyr,rlfPath,pdfPathTemp)


The policyList[0] is populated using the arcpy.da.SearchCursor() and appending the list as it reads through the attribute table.

I am using ArcGIS Server 10.2, Windows Server 2008 R2 Standard w/ SP1 and 64-bit OS.

Thanks for any guidance you can give.

Haskett
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III
arcpy.mapping.ExportReport is only supported on 32-bit versions of ArcGIS. Are you running from ArcGIS for Desktop normally? You may need to reassociate .py files with the 32 bit install's Python installation to make it functional.

View solution in original post

0 Kudos
13 Replies
JasonScheirer
Occasional Contributor III
arcpy.mapping.ExportReport is only supported on 32-bit versions of ArcGIS. Are you running from ArcGIS for Desktop normally? You may need to reassociate .py files with the 32 bit install's Python installation to make it functional.
0 Kudos
MichaelVolz
Esteemed Contributor
Can you show how you are calling the script from the Task Scheduler?

Are you calling the .py directly or are you using a bat file to call the .py file(s)?

In either case you would need to specifically tell the Task Scheduler to use the 32-bit version of python as, by default, it is probably calling the 64-bit version of python.  This is a change I needed to make on my GIS servers where there was both a 32-bit and 64-bit version of python installed (e.g. ArcGIS Desktop and ArcGIS Server software both installed on the server).
0 Kudos
BradPosthumus
Occasional Contributor II
Not sure if this has anything to do with your problem, but I found running Python scripts using Task Scheduler wouldn't consistently work if you set the Python executable as the program to run. Instead, I had to use cmd as the program with the python executable and the python script as arguments.

So for example, if my script was under C:\path\to\script.py, then I would set it up in the Task Scheduler to run cmd as the Program/Script with the arguments /c python C:\path\to\script.py (under Add arguments (optional)).
0 Kudos
GeorgeHaskett
Occasional Contributor III
Thanks,

I have to admit, that sort of makes things a bit more confusing.

Why does it work flawlessly when I manually execute it from my default Python shell and not when I use the task scheduler?
I have ran it both directly from the desktop software and from the python shell without any issues.  I'm not at work today, so I will have to wait until tomorrow to check some settings.  However I know the server is 64 bit and I am running it via the desktop software on the server.  Granted when I run the task scheduler I am running it via the 64 bit option.

Do you think it will run if I specify the 32 bit option or try to let the server choose?

Yes, in the task scheduler I am point to the 64 bit python option on the left side of the window and on the right side I am giving it the path to the python script, no bat file.

So tomorrow I will test a few of your suggestions out and see what happens.

Come to think about it, only about a third of my scripts run via the task scheduler.  All of them are via the 64 bit option.  So I stick with the 32 bit for them all if its possible or just use the cmd line and let the server sort it out?

Thanks again for your help!
0 Kudos
GeorgeHaskett
Occasional Contributor III
Brad,

I like where you are going with that idea, but I cannot get it to run using the criteria/arguments you showed.

Haskett
0 Kudos
BradPosthumus
Occasional Contributor II
The attached screenshot shows how I have one task set up (using the GUI). I suppose the only other consideration is whether you have the right version of Python running by default, but I assume you have that covered already since you can run it manually.
0 Kudos
GeorgeHaskett
Occasional Contributor III
The attached screenshot shows how I have one task set up (using the GUI). I suppose the only other consideration is whether you have the right version of Python running by default, but I assume you have that covered already since you can run it manually.


Still a No-Go for me.
I also tried it directly in my CMD window and received the following error:
[INDENT]'/c' is not recognized as an internal or external command, operable program or batch file.[/INDENT]

Does that message ring a bell?  I've added the path to the 32-bit version of python to my PATH settings and have also associated the .py files with python...

If I type the path only into my cmd line, then it runs directly from the cmd window, but again not from the task manager. 

For clarification, I am able to get it running by pointing the task manager to my python exe and adding the path to the argument section.  But not the cmd option you are using, which is what I am now trying to figure out.
0 Kudos
KevinHibma
Esri Regular Contributor
How about this way? (see attached image)
Explicitly calling Python 32bit. The main.py is in the c:\logparser folder.

[ATTACH=CONFIG]30984[/ATTACH]

note: i dont have arcgis on this machine. Otherwise the Python.exe path would be like 'C:\Python27\ArcGIS10.2\python.ext'
0 Kudos
BradPosthumus
Occasional Contributor II
Still a No-Go for me.
I also tried it directly in my CMD window and received the following error:
[INDENT]'/c' is not recognized as an internal or external command, operable program or batch file.[/INDENT]

Does that message ring a bell?  I've added the path to the 32-bit version of python to my PATH settings and have also associated the .py files with python...


/c is an option of cmd. You need to put cmd in front of it, i.e run the cmd command in the command window, as confusing as that sounds. So in the command window, type:

cmd /c python C:\script.py
0 Kudos