操作方法

操作方法:使用基于令牌的身份验证通过 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

获得人工智能支持

使用 Esri Support AI Chatbot 快速解决您的问题。

立即开始聊天

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

立即开始聊天

转至下载选项