Error 000732 when trying to use GetParameterAsText in python script tool

2651
15
08-30-2016 09:30 AM
AndrewRowlands
New Contributor

I'm attempting to write code to run a buffer and drive time analysis on an XY data file and then count features from another shapefile within the drive time trade area that's created. I'm attempting to use the Spatial Join (Analysis) for the latter process. I'm currently having an error with my code at the Spatial Join part of the code. It says the dataset "false" does not exist, which is not a dataset that I'm trying to use or am even aware of. Here is the error message with the key details:

Traceback (most recent call last):
File "Y:\BI\GIS Data\GIS Data Backup\Python Scripts\InternalModel_PythonScript_SingleSite.py", line 121, in <module>
arcpy.SpatialJoin_analysis(targetFeaturePoly, joinSpatialConvStores, outPolyCStorePoints)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\analysis.py", line 471, in SpatialJoin
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Join Features: Dataset false does not exist or is not supported
Failed to execute (SpatialJoin).

I will say, this script runs properly when I do not see the final parameter, but instead link directly to the file path in the code. It's once I try to use GetParameterAsText when the error occurs. Here is the code attached. The error is occurring in this section. When I remove the comment from line 3 and run the script directly setting that variable to the shapefile, it works fine.

#create layers for summarize within function; pull number of c-stores within drive time polygon
joinSpatialConvStores = arcpy.GetParameterAsText(2)
#joinSpatialConvStores = r"X:\Users\Andy.Rowlands\AHR.Data\MPSI_KalibrateData\MPSI_Competition_Locations\2015Surveys\DesMoines_2015_locations.shp"
targetFeaturePoly = fcDriveTimeAppend
businessPointsString = "CStoreCount_"
outPolyCStorePoints = businessPointsString + fcLocation
arcpy.SpatialJoin_analysis(targetFeaturePoly, joinSpatialConvStores, outPolyCStorePoints)
print ("CStore Count Done")
0 Kudos
15 Replies
DanPatterson_Retired
MVP Emeritus

recently discussed,... it is your path configuration, particularly the spaces, move the source file to a path without spaces, perhaps on your local drive... should that now work, I will try to locate the path issue and what getparameterastext does when paths are non-compliant

AndrewRowlands
New Contributor

Can folder names in file paths not even include underscores? Because that's what my folder path has; there are no "true" spaces.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Y:\BI\GIS Data\GIS Data Backup\Python Scripts

Don't see any underscores in the above portion... scriptname is a general indicator of potential problems, however, you will need to provide that information for confirmation... and I hope everything is locally stored, cause sometimes that raises issues with the whole unc thing... so print out the parameters, short paths, no spaces, dashes etc and if you are coding make sure you are using raw encoded filenames

ie r"c:\path_to_my\data.shp"   for example

0 Kudos
AndrewRowlands
New Contributor

I've corrected all the file paths to remove any perceived spaces, and the issue is still occurring. I don't think that was the issue as the other two GetParameter's were also pathed in similar ways. The script still works when I directly write the code linking to the file path (spaces or no spaces); it's only when I try to use a GetParameterAsText when it does not.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I agree with Dan, probably something in you paths.  Maybe the dots in this part of your path??

Andy.Rowlands\AHR.Data
0 Kudos
AndrewRowlands
New Contributor

The paths for the first two parameters are as follows, and they work perfectly.

X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\August2016\DesMoines.Hickman86th

X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\August2016\DesMoines.Hickman86th\DesMoines_Hickman_86th.csv

0 Kudos
DanPatterson_Retired
MVP Emeritus

Really?  Here is my go at your filename as a text string

>>> x = "X:\Users\Andy.Rowlands\AHR.Data\REF.Requests\August2016\DesMoines.Hickman86th"
 File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Now that was in python 3.5... That pesky folder called users, sometimes does, sometimes doesn't get interpreted as a unicode literal.  I suspect 

you are using python 2.7 which cleverly masks this flawed folder location for most things.

As a check, try moving your files out of anything that begins with a python literal... such as \t, \n, \U, \u etc,,, there are several.

If X is you working folder... and you have permissions, setup a folder structure that doesn't have those issues, doesn't have periods or spaces

and to be sure preface with an r for raw encoding.

DanPatterson_Retired
MVP Emeritus

have a read.... this is the link I was talking about ... when getparameterastext misbehaves vs python script

https://community.esri.com/message/631093-passing-arcmap-layers-to-a-python-script-inside-arctoolbox 

Xander's comments are pertinent

0 Kudos
AndrewRowlands
New Contributor

I thought that would work, but sadly, it did not. Received the same error message. One question I did have, would I change GetParameterAsText(2) to GetParameter(0) or GetParameter(2)? It would still be the third parameter in total in the script, but it would be the first parameter defined by the GetParameter function (no AsText)?

Any other thoughts?

0 Kudos