I have the following script to overwrite an existing locator service, in a standalone ArcGIS Server (10.9.1)
I'm getting the following error when creating the sd draft file
Below is the code
from arcgis.gis import server
import arcpy
import pprint
## Overwrite any existing outputs
arcpy.env.overwriteOutput = True
EGServer = server.Server(url=f"https://arcgisserver/arcgis/admin", username, password)
print(' Connected to Server')
## Create sd draft file
LocFolder = "\\\\locators\\EnerGov\\ElasticSearch"
sdFile ="\\\\c$\\Users\\AppData\\Local\\ESRI\\ArcGISPro\\\\Staging\\ arcgis\\ElasticSearchLocator.sd"
sddraftFile ="\\\\c$\\Users\\AppData\\Local\\ESRI\\ArcGISPro\\Staging\\arcgis\\ElasticSearchLocator.sddraft"
service_name = "ElasticSearchLocator"
summary = "Locator for EnerGov's elastic search"
tags = "EnerGov, locator, elastic search"
## server_connection_file has agssite login
server_connection_file = "\\\\EnerGov\\admin on arcgis.ags"
print('Creating SD draft file')
analyze_messages = arcpy.CreateGeocodeSDDraft(LocFolder,sddraftFile,service_name,server_type='ARCGIS_SERVER',
connection_file_path=server_connection_file, copy_data_to_server=True,
summary=summary, tags=tags, max_result_size=500, max_batch_size=1000,
suggested_batch_size=1000, overwrite_existing_service=True)
print(arcpy.GetMessages())
## Stage and upload the service if the sddraft analysis did not contain errors
if analyze_messages['errors'] == {}:
try:
## Convert sddraft file to a service definition (sd) file
print('Staging service')
arcpy.StageService_server(sddraftFile, sdFile)
print(' Staging Service ' + arcpy.GetMessages())
## Publish service definition (sd) file as a service
print('Publishing locator')
arcpy.UploadServiceDefinition_server(sdFile, EGServer)
print(' Publishing Service ' + arcpy.GetMessages())
except:
message = arcpy.GetMessages()
else:
# if the sddraft analysis contained errors, display them
print("Error were returned when creating service definition draft")
pprint.pprint(analyze_messages['errors'], indent=2)
print("Done!!")
The code was originally shared by ArcGIS Geocoding Team here
Any pointers would be appreciated.
I'd venture to say that it is having problems with the way the paths are coded. The ValueError that you blanked out means that it's a bad value for what the tool expects.
I could be wrong, but I've never seen the paths start out from the c drive like \\c$. I've always set the server server name like \\servername\\c$\\ or fullservername.com\\c$\\ to tell the script what c: do go to, even if its on the same server. Print out the full path and copy and paste it into explorer to see if it is valid.
You also have a space before the arcgis in the path, and a couple extra \\ before Staging that could be an issue as well:
sdFile ="\\\\c$\\Users\\AppData\\Local\\ESRI\\ArcGISPro\\\\Staging\\ arcgis
Thanks for catching the extra \\ on the sdFile variable.
I made a copy of the locator and moved it to a different folder. The error message is the same with the updated folder path.
You'll need to go through all of your connection/ paths in your code and make sure they are valid, <i.e., copy paste them from your code into windows explorer and make sure it takes you to the right location.>
Yes, I already did that and all the paths are correct.
@AliciaShyu- Did you ever figure out what triggered this? We finally upgraded one of our servers to 10.9.1 and am getting the same issue as you did back in 2022. Our folder paths and file paths are very generic and non-problematic, so we've ruled that out. Our other server is still on 10.8.1 and is not triggering failures using the same scripts. Something with the upgrade to 10.9.1 has caused a change that we haven't identified yet. Thanks for any insight!
Disregard. We sorted it out. Turns out Enterprise 10.9.1 did *not* like our .ags connection file for whatever reason. Maybe it was a legacy .ags file created from an older version of ArcMap...? Anyway, I recreated it within ArcGIS Pro 3.3.1 with refreshed credentials, and now it's functioning again as expected. I hope this is helpful to anyone else who encounters the ValueError issue with the .ags connection string.