是否有可能生成永不过期的arcgis令牌

问题描述 投票:0回答:1

我不是arcgis的新手,所以请让我知道我要尝试的方法不是应该如何做。

我有一个服务器应用程序,它会定期对某些数据进行分析,然后通过python arcgis软件包将该数据以CSV的形式发布回arcgis。然后将其显示在arcgis的仪表板上。

我的问题是我找不到生成不会过期的令牌的方法。我更喜欢存储令牌,而不是用户名/密码,并且我不能执行OAuth2,因为这是定期的后台任务...

是否可以生成这样的令牌?

我设法在arcgis中注册了一个应用程序,并从中获得client_id和client_secret,我可以用它来调用arcgis.com/sharing/rest/oauth2/token并生成一个令牌,该令牌可以在会话期间使用,但是该令牌不允许我打电话给GIS.item.updateGIS.item.publish ...

这是我用于生成和使用令牌的代码:

from arcgis.gis import GIS
import json
from urllib3 import PoolManager
from urllib3.exceptions import HTTPError

url = "https://www.arcgis.com/sharing/rest/oauth2/token"

payload = "client_id=my_client_id&client_secret=my_secret&grant_type=client_credentials"
headers = {
    'content-type': "application/x-www-form-urlencoded",
    'accept': "application/json",
    'cache-control': "no-cache", }

pool_manager = PoolManager()

try:
    response = pool_manager.request(method="POST", url=url, headers=headers, body=payload, retries=3)
    token = json.loads(response.data)["access_token"]
    print(token) # Token gets generated without any problem
except HTTPError as e:
    print(str(e))

g = GIS(token=token)
i = g.content.get(my_arcgis_item_id)
i.download("/tmp", file_name="my_file_name") # no permission issues here

device_properties = {
    "title": "test",
    "tags": "test",
    "type": "CSV"}

i.update(item_properties=device_properties, data="/tmp/my_file_name") # <-- this fails

如果我使用通过REST API生成的令牌,则以上最后一步将失败。如果我只是从https://developers.arcgis.com/dashboard复制/粘贴令牌,那么我不会遇到任何授权问题(但是此令牌是临时令牌...)

python arcgis
1个回答
0
投票

解决方案可能是获取使用oauth2生成的授权令牌,然后使用刷新令牌定期重新生成令牌(https://developers.arcgis.com/rest/users-groups-and-items/token.htm]

© www.soinside.com 2019 - 2024. All rights reserved.