Windows Scheduler run Python issue - ERROR 000732

4964
9
Jump to solution
08-06-2013 12:42 PM
JulieYuan
New Contributor II
OS: Windows Server 2008 R2
Python 2.7.2
Arcgis 10.1

I have created a toolset GPS_SPEED, Model name: Speed.


Python script is very simple, as below.
DOS Command Line run successfully. No except error message.
Using Windows Task Scheduler run python, The error raised at â??arcpy.Speed_TBX()â??.

Erro Log:
Failed to execute. Parameters are not valid.
ERROR 000732: Join Features: Dataset Y:\Data\Current\ROADBUFFERLL.shp does not exist or is not supported
Failed to execute (Speed).

checked Y:\Data\Current\ROADBUFFERLL.shp, it is correct.

----------------------------Script------------------------------
# Import arcpy module
import arcpy

# Log file
logfile = "C:\\arcgis\\scripts\\log\\speedreturn2.log"
f = open(logfile, 'w')

arcpy.ImportToolbox(r"C:\arcgis\Tools\GPS_speed.tbx", "TBX")

try:
arcpy.Speed_TBX()
f.close()
except:
f.write(arcpy.GetMessages(2))
f.close()
----------------------------End Script------------------------------

Any suggestion are greatly appreciated.

Julie
1 Solution

Accepted Solutions
DaleHoneycutt
Occasional Contributor III
The only thing I can think of is that the task is running under a different user that doesn't have access to your Y: drive.  Check the properties of your scheduled task.  In Windows 7, the task scheduler has a "When running a task, use the following user account" option.  Is it the same account that you are logged into when you run from DOS?

View solution in original post

0 Kudos
9 Replies
DaleHoneycutt
Occasional Contributor III
The only thing I can think of is that the task is running under a different user that doesn't have access to your Y: drive.  Check the properties of your scheduled task.  In Windows 7, the task scheduler has a "When running a task, use the following user account" option.  Is it the same account that you are logged into when you run from DOS?
0 Kudos
Luke_Pinner
MVP Regular Contributor
Just for info, here's a link to instructions on how to post Python code.

# Import arcpy module
import arcpy

# Log file
logfile = "C:\\arcgis\\scripts\\log\\speedreturn2.log"
f = open(logfile, 'w')

arcpy.ImportToolbox(r"C:\arcgis\Tools\GPS_speed.tbx", "TBX")

try:
    arcpy.Speed_TBX()
    f.close()
except:
    f.write(arcpy.GetMessages(2))
    f.close()
0 Kudos
JulieYuan
New Contributor II
The only thing I can think of is that the task is running under a different user that doesn't have access to your Y: drive.  Check the properties of your scheduled task.  In Windows 7, the task scheduler has a "When running a task, use the following user account" option.  Is it the same account that you are logged into when you run from DOS?


dmhoneycutt, Thank you very much. The problem solved.
I used the same user to run the DOS command and Schedule Task. But the Y drive is remote map network drive. I think when the user log in, the drive is connected and mapped. But the Schedule Task didn't have the drive exist.
Added the command before run the Python. It works.
net use Y: /d /Y
net use Y: \\adminfs\gis
IF EXIST "Y:\Data\Current\ROADBUFFERLL.shp"  echo "Y:\Data\Current\ROADBUFFERLL.shp exist" >>C:\arcgis\scripts\log\speedreturn.log
C:\Python27\ArcGIS10.1\python.exe C:\arcgis\Tools\SpeedReturn.py  



Thanks again.

Julie
0 Kudos
DaleHoneycutt
Occasional Contributor III
Julie:
Very nice solution!  I like the way you used DOS commands to echo the existence of the file.  I did not know about the DOS command NET USE.  So I did a little investigation and thought I'd pass on what I found out to other readers of this post.

To learn about NET USE, enter this at the DOS command prompt:
NET USE /HELP
lower case is supported, so you can also type:
net use /help


So, I figured out that your line:
net use Y: \\adminfs\gis
Is mapping the Y: drive to \\adminfs\gis

As best I can figure out, the first line:
net use Y: /d /Y
is actually shorthand for:
net use Y: /delete /YES
which removes the existing connection to the Y: drive (/delete) then instructs DOS to remember any subsequent mapping you make.  Is this correct?

By the way, we just wrote a blog post about scheduling tasks so this thread is particularly timely.   If you could confirm that net use Y: /d /Y
is doing what I think it does, I'll add some more to the blog post about using the NET USE command.

Thanks again,
Dale
0 Kudos
JulieYuan
New Contributor II
Julie:

So, I figured out that your line:
net use Y: \\adminfs\gis
Is mapping the Y: drive to \\adminfs\gis

As best I can figure out, the first line:
net use Y: /d /Y
is actually shorthand for:
net use Y: /delete /YES
which removes the existing connection to the Y: drive (/delete) then instructs DOS to remember any subsequent mapping you make.  Is this correct?

Thanks again,
Dale


Dale,
You are 100% correct. net use Y: /d /Y is remove the existing connection.

Thanks making the documents clear and organized.

Julie
0 Kudos
by Anonymous User
Not applicable
I agree that Julie had a pretty cool workaround, was even worth a vote up!  I did not know about the "net use" command either.  But wouldn't it be easier to just use the full UNC path in the model?  That way you would not need to fuss with remapping the network drive. 

It may not be the case, but if the user's have different mapped network drives and they run a tool and it overwrites their prior mapped drive settings, that could anger a lot of users! 

Here's a quick test:

>>> import arcpy
>>> # mapped network drive test
>>> shp = r'G:\Data\Shapefiles\Census_CedarCo\Block_Groups.shp'
>>> if arcpy.Exists(shp):
 print 'yes'

 
yes
>>> # UNC path test
>>> shp = r'\\ccgis\Cedar_CO_GIS\Data\Shapefiles\Census_CedarCo\Block_Groups.shp'
>>> if arcpy.Exists(shp):
 print 'yes'

 
yes


I think using the full UNC path would be the safest way, although remapping the network drive with the command prompt was pretty cool!
0 Kudos
DaleHoneycutt
Occasional Contributor III
I totally agree that UNC paths would be better.  My takeaway from this, for debugging purposes, is:


[INDENT]If you have data access problems, look for suspicious drive letters like Y: instead of the typical C: 😧 and E: .  It usually implies that a network drive has been mapped and the mapping no longer exists, or cannot be found by the scheduled task.  You can either change the script or model being run to use a UNC path instead of a drive letter, or, as an alternative when modifying the model or script is difficult, use the NET USE stuff...[/INDENT]
0 Kudos
by Anonymous User
Not applicable
I totally agree that UNC paths would be better.  My takeaway from this, for debugging purposes, is:


[INDENT]If you have data access problems, look for suspicious drive letters like Y: instead of the typical C: 😧 and E: .  It usually implies that a network drive has been mapped and the mapping no longer exists, or cannot be found by the scheduled task.  You can either change the script or model being run to use a UNC path instead of a drive letter, or, as an alternative when modifying the model or script is difficult, use the NET USE stuff...[/INDENT]


Good point.
0 Kudos
DarrylKlassen
New Contributor III
Just a further note to this - you can run the NET USE command from within Python.

import os
os.system("net use y: \\path\\to\\folder")

In case you don't want to do it in DOS before running the PY script.

Darryl