Using administrative capabilities of ArcGIS Python API with a standalone AGS server

453
3
10-31-2023 10:01 PM
Labels (2)
eMosby
by
New Contributor II

I am trying to use the ArcGIS API for Python (Python 3.9) to access admin capabilities of an unfederated ArcGIS (10.6.1) Site. The site is comprised of a multimachine deployment behind a single web adaptor. The site's web adaptor and associated AGS machines also sit behind a reverse proxy server.

This is my Python code to get a Server object:

from arcgis.gis.server import Server
ags_url = 'https://webadaptor.domain.org/arcgis/admin'
server = Server(url=ags_url, username=user, password=password, verify_cert=False)

The specific error that is blocking me is:

"Unauthorized access. Token not found. You can generate a token using the 'generateToken' operation."

I am passing valid ArcGIS Server credentials. I have also tried passing the '/arcgis/admin/generateToken' appended url to tokenurl and token_url as parameters (the docs/forum usage seems to vary)

In a browser, if I hit the generateToken endpoint (via html) with the credentials and the 'Request IP' <Client> parameter, I seem to receive a valid token:

eMosby_0-1698813184357.png

JSON response:

{
  "token": "blahblahblalyjfkutrk8htdkhg-khfu4twujt73g0irsdkgjh",
  "expires": "1698816744485"
}

Accordingly, I can access the admin endpoint and do various admin things from my machine in a browser using the same credentials.

In Python, I can successfully create a server object with the inputs stated, but it seems no administrative privileges are granted. The privileged properties return a stack trace error in my IDE. I can see the server version, etc. & ServiceDirectory of the site but nothing else.

I suspect that the reverse proxy server is somehow contributing to the token error, but I am at a loss as to how to rectify it.

How do I get a token to the API so that I can administer the site programmatically?

0 Kudos
3 Replies
eMosby
by
New Contributor II

This seems relevant even though it is for Enterprise. Getting closer, but could still use help.
If I can get a token via POST, how do I use it with the ArcGIS Python API?

https://enterprise.arcgis.com/en/server/latest/administer/windows/acquiring-arcgis-tokens.htm

Note:

If there is a proxy server between the client application or browser and the ArcGIS Server site, tokens generated using the IP Address and IP address of this request's origin options must be bound to the IP address of the proxy server. If there are multiple load balancing proxy servers between the client application or browser and the ArcGIS Server, the HTTP Referer option should be used.

0 Kudos
DanielBrumm1
Occasional Contributor II
0 Kudos
eMosby
by
New Contributor II

Thanks for your reply. I had not seen that particular doc, but what it describes is what I have tried to do.

I believe my issue is that the parameters the generateToken function accepts (at least as enumerated therein) are only user and password. I suspect with our deployment architecture the username/password are not enough to generate a token and what is also needed is the 'request IP' (the proxy server's IP).

In any case, now it seems I should probably try to get a token response via a separate REST call to the generateToken endpoint and pass it as a parameter to the Server() method, or attempt to pass the additional generateToken parameters here directly.

0 Kudos