CÓMO

Sincronizar un elemento de data store con un script de Python utilizando la autenticación basada en token

Last Published: September 12, 2023

Resumen

Starting with Portal for ArcGIS 10.7.1, users can register user-manager data stores by adding a data store item to the portal. When a user's create data stores items in their portal organization, it allows users to create web layers in bulk from the items inside the enterprise geodatabase.

Causa

When items are added or removed from the enterprise geodatabase, users can manually synchronize the enterprise geodatabase with the data store item in the portal. However, some users may want to automate the syncing process using a Python script. 

Procedimiento

Below is one method to synchronize the data store item with Python: 

import urllib, urllib2, json, ssl, arcpy, requests

# Generate Portal token
username = "<enter user name>"
password = "<enter password>"

tokenURL = 'https://<enter portal URL>/portal/sharing/rest/generateToken/'
param_1 = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://<enter portal URL without web adaptor>'}
req = urllib2.Request(tokenURL, urllib.urlencode(param_1))
try:
    response = urllib2.urlopen(req)
except:
    gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    response = urllib2.urlopen(req, context=gcontext)
data = json.load(response)
token = data['token']
print(token)


# Sync the Data Store item in Portal
publishURL = 'https://<enter portal URL>/portal/sharing/rest/portals/self/datastores/allDatasets/publishLayers'
param_2 = {'datastoreId': '<enter datastore ID>',
                   'templateSvcConfig': {"serviceName":'null',"type":"MapServer","capabilities":"Map,Query","extensions":[{"typeName":"FeatureServer","capabilities":"Query","enabled":"true","properties":{"maxRecordCount":"4000"}}]},
                   'f': 'json',
                   'token': token}
req = urllib2.Request(publishURL, urllib.urlencode(param_2))
try:
    response = urllib2.urlopen(req)
except:
    gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    response = urllib2.urlopen(req, context=gcontext)
data = json.load(response)

print('Syncing')

Id. de artículo: 000022854

Recibir notificaciones y encontrar soluciones a problemas nuevos o comunes

Obtenga respuestas resumidas y soluciones de vídeo de nuestro nuevo chatbot de IA.

Descargar la aplicación de soporte de Esri

Información relacionada

Descubrir más sobre este tema

Obtener ayuda de expertos en ArcGIS

Contactar con el soporte técnico

Descargar la aplicación de soporte de Esri

Ir a opciones de descarga