HOW TO

Synchronisieren eines Data Store-Elements mit einem Python-Skript bei Verwendung der tokenbasierten Authentifizierung

Last Published: September 12, 2023

Zusammenfassung

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.

Ursache

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. 

Vorgehensweise

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')

Artikel-ID: 000022854

Benachrichtigungen erhalten und Lösungen für neue oder häufige Probleme finden

Unser neuer KI-Chatbot stellt zusammengefasste Antworten und Videolösungen für Sie bereit.

Esri Support App herunterladen

Zugehörige Informationen

Weitere Informationen zu diesem Thema erkunden

Unterstützung durch ArcGIS-Experten anfordern

An den technischen Support wenden

Esri Support App herunterladen

Zu Download-Optionen wechseln