Hello all,
I am trying to write a stand alone python script that accesses a REST API feature service using ArcGIS Python for API. The service is sitting in a portal of my organisation.
When using ArcGIS pro, I am supposed to use a Single Sign On system for an authentication to access the service that means I do not have a built-in account for the portal to use in the script.
I may be wrong but I understand that I need to configure a proxy server in the script by providing my own login credential to a proxy server.
But I am new to Python API, I don't know an appropriate way to achieve this.
Much appreciated if anyone could tell me some solutions.
Usually I just use my username and password, it's using Active Directory for authentication but it still works with the Python API.
from arcgis.gis import GIS
PORTAL_URL="https://myportal/portal"
PORTAL_USER="bwilson@WINDOWSDOMAIN"
PORTAL_PASSWORD="my active directory password"
gis = GIS(PORTAL_URL, PORTAL_USER, PORTAL_PASSWORD)
It's possible to create a token in Portal and then use the token in your script. I'm sure I messed around with that a few months ago? If you go to the "portaladmin" site you can get a token with an expiration time and a URL to limit it The URL is like https://YOURPORTALNAME/portal/portaladmin and click "Generate Token".
So go generate a token, then copy the string and paste it, something like this:
token = "yBj8Gde3jFvLqbCWIyAG5p5fi0-lK8liEjd9JfPFD2ez2zEvoLlRnmHayZNEeqaoo98Cx0xRqiem-wLaCEKTE7KGyaXv3fRytAg7foDE8ugPdx9p7hrk-_RFPv63NwG9-i9tEjSh9snfb4xGcygM4q4FnmrNw8OM48k3GAie-UFVQaIU1Df065AHZkBTCG-xh1AOMr3FWW5vbHQw.."
gis = GIS(PORTAL_URL,api_key=token)
print(gis)
q = '*'
list_of_maps = gis.content.search(
q, item_type='web map', outside_org=False, max_items=5000)
print("Maps found %d" % len(list_of_maps))
on my computer this generated text like this
GIS @ https://MYURL/portal version:8.4
Maps found 50
Thanks for your suggestion. Unfortunately, as I am not an administrator for the portal, I cannot log in the admin site to generate Token.
Since I do not have my own username and password for the portal, I obtained "Client ID" to use "ArcGIS Python API supports OAuth 2.0 as an authentication method" (https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/)
from arcgis.gis import GIS
gis = GIS("https://************/portal", client_id='*********')
print("Successfully logged in as: " + gis.properties.user.username)
but this still did not success for some reasons