I have a script that creates two geolocators and publishes one of them to our standalone ArcGIS Server (10.7.1). When I run it in Python IDLE 3.6.8 it fails. When I run the exact same script in Python 2.7, it succeeds. I'm trying to get away from using 2.7, but I have a very similar issue with another important script that won't run in Pro or 3.6.8 due to a bug. Is anyone having trouble with Server publishing in Python 3.6.8?
Here is the error that I get in the script and in the server logs. There is nothing specific in the server logs, just this:
An error occurred
ERROR 001487: Failed to update the published service with the server-side data location. Please see the server's log for more details.
ERROR 001369: Failed to create the service.
Failed to execute (Publish Service Definition).
Failed.
Failed to execute (Publish Service Definition).
Failed.
Failed to execute (UploadServiceDefinition).
Here is the relevant snippet of the script:
##Publish locators to ArcGIS Server
locator_path = geocoding_dir + "COP_Master_Address_Locator.loc"
sddraft_file = geocoding_dir + "COP_MAF_locator.sddraft"
sd_file = geocoding_dir + "COP_MAF_locator.sd"
service_name = "COP_Master_Address_Locator_test"
summary = "Locator based on City Master Address Points"
tags = "Geolocator"
gis_server_connection_file = r"path\to\myconnection.ags"
# Create the sd draft file
analyze_messages = arcpy.CreateGeocodeSDDraft(locator_path, sddraft_file, service_name,
connection_file_path=gis_server_connection_file,
summary=summary, tags=tags, max_result_size=5,
max_batch_size=100000, suggested_batch_size=10000,
) ##overwrite_existing_service=True
# Stage and upload the service if the sddraft analysis did not contain errors
if analyze_messages['errors'] == {}:
try:
# Execute StageService to convert sddraft file to a service definition
# (sd) file
arcpy.server.StageService(sddraft_file, sd_file)
# Execute UploadServiceDefinition to publish the service definition
# file as a service
arcpy.server.UploadServiceDefinition(sd_file, gis_server_connection_file)
print("The geocode service was successfully published")
except arcpy.ExecuteError:
print("An error occurred")
print(arcpy.GetMessages(2))
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)
Solved! Go to Solution.
Hi Levi,
In Python 3.6, you have to add copy_data_to_server=True as one of the parameters to the "CreateGeocodeSDDraft" call. That will get rid of ERROR 001487.
It sounds like you already have a service called COP_Master_Address_Locator, so you'll have to also pass the overwrite_existing_service=True.
Passing those 2 arguments in Python 3.6 should solve your problem.
Thanks,
Victor
The problem is with the argument overwrite_existing_service=True. If I remove this from the arcpy.CreateGeocodeSDDraft tool in Python 3.6, I get ERROR 001398: Service name 'COP_Master_Address_Locator' already exists. Failed to execute (UploadServiceDefinition).If I put it back in I get the aforementioned errors. If I run this script in Python 2.7 with overwrite_existing_service=True. the script says this is an unexpected argument. If I run it without that line the script will overwrite the previous locator on the server. So as it stands, I'll have to split this into two scripts between Python 2.7 and 3.6 to get it to work.
If your data is being updated on some periodic basis, why don't you try manually creating the gocode service and then have scripts that stop the service, then rebuild the address locator and finally start the service.
Hi Levi,
In Python 3.6, you have to add copy_data_to_server=True as one of the parameters to the "CreateGeocodeSDDraft" call. That will get rid of ERROR 001487.
It sounds like you already have a service called COP_Master_Address_Locator, so you'll have to also pass the overwrite_existing_service=True.
Passing those 2 arguments in Python 3.6 should solve your problem.
Thanks,
Victor