Select to view content in your preferred language

Exception: Unable to generate oauth token

2651
9
10-14-2023 01:30 AM
TZ
by
Occasional Contributor

I am trying to Connect to ArcGIS Enterprise v11.1 using a built-in account as described in tutorial --> https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/#User-authe...

Here is my entire code:

---------------------------------------------------------

from arcgis.gis import GIS

portal_url = 'https://myserver.org/portal/portaladmin/'

username = 'portaladmin'

password = 'pasw1234'

print("Portal for ArcGIS as a built in user")
gis = GIS(portal_url, username, password)
print("Logged in as: " + gis.properties.user.username)
 
------------------------------------------------
i get this error:
 
Exception: Unable to generate oauth token
 
How to solve this? Do i have to register this simple script as an App in Azure AD or something?

 

 

9 Replies
EarlMedina
Esri Regular Contributor

Remove "portaladmin". It should be: "https://myserver.org/portal" from your example.

0 Kudos
TZ
by
Occasional Contributor

I changed the "portal_url" value to "https://myserver.org/portal" as per your suggestion but still get the same error "Unable to generate oauth token", the only difference being an informational message "Portal for ArcGIS as a built in user" in the output at the very beginning.

Are there any more guides regarding setting up OAuth for ArcGIS Python API aside this very scant page ? --> https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/#User-authe...

TZ
by
Occasional Contributor

and what about my previous question - do i have to register this modest script as an app in Azure AD or not??

0 Kudos
EarlMedina
Esri Regular Contributor

Are you saying this is in fact not a built in user? Are you actually using Azure AD? DO you happen to know how the portal was sconfigured?

0 Kudos
ellipsol
Regular Contributor

I started seeing this same issue that started yesterday. Do you have a solution or work-around? I've been using this calls in scripts for more than a year, no problem until now.

ellipsol_0-1697751666618.png

 

0 Kudos
ellipsol
Regular Contributor

My proxy changed and that was what was causing this error. It is resolved now.

0 Kudos
Danfranco
Emerging Contributor

where are you specifying the proxy changes? I have a very similar issue, but I know nothing has changed....

0 Kudos
ellipsol
Regular Contributor

I had a proxy in my browser settings. My employer stopped using that proxy though and it caused these errors. It was fine once I turned off the "Manual proxy setup" in Chrome. These days I use a profile to log in. You can set up in a notebook from Pro.

### Set up a profile
from arcgis.gis import GIS
gis_profile = GIS("https://subdomain.maps.arcgis.com", "un", "pw", profile="gisprof")
print("Profile defined for {}".format(gis_profile))

 

And then in my scripts I call:

mygis = GIS("https://subdomain.maps.arcgis.com", profile="gisprof")
print("Connected to the GIS as {}.".format(mygis.properties.user.username))

 

Does that work for you?

0 Kudos
Danfranco
Emerging Contributor

The only things I have seen work (dependent on your Pro version) are use_gen_token=True, which ignores oAuth and uses the built-in users you have.

However, this is the issue I am experiencing now, where it causes issues if its not added i.e. it won't login without use_gen_token, but then when trying to query a layer I get an invalid token.

The documentation is rather poor, and every pro upgrade, is a finger in the air as to whether your existing code will work 🙂

0 Kudos