方法

Python スクリプトでトークン ベースの認証を使用してデータ ストア アイテムを同期する

Last Published: September 12, 2023

サマリー

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.

原因

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. 

手順

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: 000022854

AI によるサポートを受ける

Esri サポート AI チャットボットを使用して問題を迅速に解決します。

今すぐチャットを開始

関連情報

このトピックについてさらに調べる

ArcGIS エキスパートのサポートを受ける

テクニカル サポートへのお問い合わせ

今すぐチャットを開始

ダウンロード オプションに移動