I created a Python script that consumes a service from a locator and a feature service. When I enter an address into the tool, it retrieves all the suggestions and adds them to the feature service with the address and geometry. I generate the tool, and it works fine for me locally; I run the tool, it prompts me for the parameter, and it edits the feature service. The problem I have is when I try to publish it. I can publish it normally, but when I try to use the service, the role that the suggest takes (arcgis.geocoding module) returns something different from when I run it locally.
address = arcpy.GetParameterAsText(0)
# Conectarse al portal de ArcGIS
gis = GIS("portal", "user","pass")
# URL del servicio de geocodificación
url_servicio = " "
#URL del feature service
url_feature_service = " "
portal_item = gis.content.get(" ")
ports_layer = portal_item.layers[0]
arcpy.AddMessage("Conectándose al locator...")
#Conectar al locator
geocodificador = Geocoder(url_servicio, gis)
def add_features(direccion):
# Obtener sugerencias de geocodificación para la dirección
arcpy.AddMessage("Obteniendo sugerencias de geocodificación para la dirección...")
sugerencias = suggest(direccion, geocoder=geocodificador)
arcpy.AddMessage("Creando puntos en el feature layer...")
# Crear puntos en el feature layer con las coordenadas de las ubicaciones sugeridas
for sugerencia in sugerencias['suggestions']:
direccion_sugerida = sugerencia['text']
ubicacion = geocode(direccion_sugerida, geocoder=geocodificador, out_sr=4326)[0]['location']
new_feature = {"attributes":
{"direccion": direccion_sugerida},
"geometry": ubicacion}
# Agregar el nuevo registro al feature layer
ports_layer.edit_features(adds=[new_feature])
arcpy.AddMessage("Ejecutando el geoproceso...")
add_features(address)
When I run it locally
{'suggestions': [{'text': 'CL 2B 18 27, CALI, VALLE DEL CAUCA, COL', 'magicKey': 'U3ViU291cmNlTmFtZT1Mb2NhdG9yR2RPRXN0cnVjdHVyYWRhfExvY2F0b3JDb21wdWVzdG9DYXVjYVZhbGxlVjEjbGJzPTE0OjE3NTAyMSNsbmc9MSNsb2M9MSNwbD0xNDY5NyN0cD0wI3R2PTY1YTI5NTk1', 'isCollection': False}, {'text': 'CL 2B 18 28, CALI, VALLE DEL CAUCA, COL', 'magicKey': 'U3ViU291cmNlTmFtZT1Mb2NhdG9yR2RPRXN0cnVjdHVyYWRhfExvY2F0b3JDb21wdWVzdG9DYXVjYVZhbGxlVjEjbGJzPTE0OjE3NTAyMiNsbmc9MSNsb2M9MSNwbD0yMDc2MDcjdHA9MCN0dj02NWEyOTU5NQ==', 'isCollection': False}, {'text': 'CL 2B 18 29, CALI, VALLE DEL CAUCA, COL', 'magicKey':
When I run it as service on portal
esriJobMessageTypeInformative: {'currentVersion': 11.2, 'serviceDescription': '', 'addressFields': [{'name': 'Address', 'type': 'esriFieldTypeString', 'alias': 'Address or Place', 'required': False, 'length': 100, 'localizedNames':
Since there are no "suggestions" the script fails:
in add_features for sugerencia in sugerencias['suggestions']: KeyError: 'suggestions'
I hope you can help me, thank you.