Select to view content in your preferred language

Create Geocode SD Draft error

2238
17
Jump to solution
07-21-2022 11:32 AM
AliciaShyu
Frequent Contributor

I have a script to overwrite an existing locator service, in a standalone ArcGIS Server (10.9.1) The code was originally shared by ArcGIS Geocoding Team here

I'm getting the following error when creating the sd draft file

t6vk6pW5G6.jpg

I already checked and all my paths are correct. Any ideas?

import arcpy
import pprint
from arcgis.gis import server

## Sign in to server
# this connects to a standalone server that has web adaptor installed
EGServer = server.Server(url=f"https://arcgis:6443/arcgis/admin", username, password)
print(' Connected to server')


# Overwrite any existing outputs
arcpy.env.overwriteOutput = True

locator_path = "\\\\xxxx\\xxxx\\arcgissource\\locators\\EnerGov\\ElasticSearch"
sdDraft ="\\\\xxxx\\xxxx\\arcgissource\\locators\\EnerGov\\ElasticSearch\\ElasticSearchLocator.sddraft"
sd_file = "\\\\xxxx\\xxxx\\arcgissource\\locators\\EnerGov\\ElasticSearch\\ElasticSearchLocator.sd"
service_name = "ElasticSearchLocator"
summary = "Locator for EnerGov's elastic search"
tags = "EnerGov, locator, elastic search"


## server_connection_file has agssite login
server_connection_file = "\\\\xxxx\\xxxx\\arcgissource\\locators\\EnerGov\\admin on arcgis_6443.ags"

# Create the sd draft file
analyze_messages = arcpy.CreateGeocodeSDDraft(locator_path, sdDraft, service_name,
            server_connection_file, copy_data_to_server=True, summary=summary, 
            tags=tags, max_result_size=20,max_batch_size=500, 
            suggested_batch_size=150, overwrite_existing_service=True)
print("Creating SD Draft file")
print(arcpy.GetMessages())
## 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.StageService_server(sdDraft, sd_file)

        # Execute UploadServiceDefinition to publish the service definition
        # file as a service
        arcpy.UploadServiceDefinition_server(sd_file, EGServer)
        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)

 

 

0 Kudos
17 Replies
AliciaShyu
Frequent Contributor

Our locators are filed based in a shared directory that has been shared with the server.

0 Kudos
bbaker_tngeo
Regular Contributor

Hi @AliciaShyu ,

I'm trying to work through a similar scenario that you described. I used to use the following code to stop/start the service, but I now get the following error: 

Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py", line 87, in __getattr__
    return self._properties.__getitem__(name)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\common\_mixins.py", line 342, in __getitem__
    return self._mapping[key]
KeyError: 'services'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\Documents\ArcGIS\Projects\Locator_Rebuild_Test\RebuildTestLocators.py", line 17, in <module>
    print(server.services.list)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py", line 93, in __getattr__
    "'%s' object has no attribute '%s'" % (type(self).__name__, name)
AttributeError: 'Server' object has no attribute 'services'

 

gis_servers = gis.admin.servers.list()

#To stop specific service(s)
for server in gis_servers:
    for service in server.services.list(folder="Locators"):
        if service.properties.serviceName == "Locator_name":
            service.stop()

 

 Is there a different way to stop a service? All the esri documentation I've found still points to this code.

Managing your GIS servers | ArcGIS API for Python

https://support.esri.com/en-us/knowledge-base/how-to-stop-gis-services-using-arcgis-api-for-python-0...

0 Kudos
AliciaShyu
Frequent Contributor

The code you have to stop the service is correct. That's what I'm using in my script to rebuild the locator.

0 Kudos
MichaelVolz
Esteemed Contributor

What version of python are you using to run the script to stop the service?

Python bundled with 2.9.x used to work for me, but when I upgraded the machine to Pro 3.x and the associated python version the script no longer runs.  BUG-000155115 does not allow the stop/start service python script to run.

0 Kudos
RonnieRichards
Frequent Contributor

@MichaelVolz  I have the same problem AttributeError: 'Server' object has no attribute 'services' with ArcGIS Pro 3.1.3 with arcgis api 2.1.0.3

 

0 Kudos
bbaker_tngeo
Regular Contributor

@MichaelVolz  and @RonnieRichards ,

I found this thread in Ideas and it appears it's been an issue for a while, with no solution in sight. From what I read, the recommended "workaround" is to stop services manually through Server Manager...

ArcGIS Pro functions for map services - Esri Community

0 Kudos
RonnieRichards
Frequent Contributor

@bbaker_tngeo it does not appear the ArcGIS Server management tools are in Pro yet. However i would not recommend this stop , rebuild and start workflow for geocoding its messy and we have had locators get corrupted on rebuild and then your service will not start.

This is possible using the service publication tools with the overwrite flag set to true. There is an example script here and it works for both stand alone and portal (with a few tweaks). 

CreateGeocodeSDDraft—ArcGIS Pro | Documentation

We do this daily by scripting backup the existing locator, rebuild locator , create the sd draft and then upload to server. If the rebuild fails the service is still running. 

bbaker_tngeo
Regular Contributor

That's the conclusion I arrived at as well. Initially, this was not possible because the locator I was working with was in a folder registered with the server so (I think) that's why it had to be stopped before it could be rebuilt.  Now the locator is in a local folder and can utilize the SDDraft replacement workflow. I had not included a backup step in the script, however, so thanks for that insight. It is definitely a good precaution.

0 Kudos