Hello,
I'm working on automating a process by creating a script that basically takes rows from a specified CSV file and adds them as features to an existing Hosted Feature Layer on ArcGIS Online.
I'd gotten this working previously, but as of the last few days, it's stopped working. The code runs, but nothing happens -- no new rows, no error message, nothing. So, I started checking components to see where the breakdown was.
My first check was the target layer pathway, "https://services.arcgis.com/[mapID]/arcgis/rest/services/[mapname]/FeatureServer/0", which, when copied and pasted into a browser, now says "Token Required". This is the same message I receive when I navigate to the page in browser, via Content > Feature Layer (Hosted) > Layers > URL (in the lower right) > View. If I click View directly (as an overlay) it works fine, but if I open it as a new tab, it presents the Token Required message. I'm familiar with this pathway for finding the accurate REST link despite that, but my understanding is that tokens are temporary, meaning hardcoding in one that was harvested from that approach would not work for long, undermining the point of automation. This does tell me that something is happening that is preventing direct connection to the feature layer, which is causing the script failure.
This suggested to me that perhaps something went wrong in the log-in or session ID phase of the code, so I tested some more, and I think something might be going on with the session.
We're a SAML (Azure AD) environment, but as per the documentation OAuth2.0 requires user interaction in its client_id approach (again defeating the purpose of automation), so I instead use my ArcGIS Pro portal connection to connect to my Enterprise ArcGIS Online environment, using
gis = GIS('pro')which I then confirmed success of, using
print(gis.users.me)
print("Logged in as " + str(gis.properties.user.username))both of which return the expected username value. This indicates (as far as I can tell) that the log-in was successful and the Pro portal pathway is working as expected. Furthermore, I can confirm session information, as
sessionInfo = gis._con._session
print(sessionInfo)
returns "<ArcGIS Session 0.1.0>" with no errors.
However, when I try to get a token based on this session, it fails.
token = gis.session.auth.token
returns an error as follows:
Traceback (most recent call last):
File "C:\Users\[username]\Downloads\1.py", line 13, in <module>
token = gis.session.auth.token
AttributeError: 'GIS' object has no attribute 'session'
I have not been able to find any information online about anyone else who has experienced this specific error. The confirmations of my username and session number suggest that there is indeed a successful session established by the log-in command, but... perhaps it's one that the script cannot fully access?
I've tried logging out of and back into ArcGIS Pro (Portal), logging out of and back into ArcGIS Online, clearing ArcGIS Pro's cache, and restarting my machine, to no avail.
What am I missing here? How can I get my Pro-portal login method to consistently generate a usable session so I can push data to my Hosted Layer?