Access published service when logged out of Portal

147
1
2 weeks ago
Labels (2)
LindseyStone
Occasional Contributor III

I'm trying to create a script that will run as scheduled task on a server that has Pro installed but Pro may not be logged into my Portal at all times.

I have it working correctly when I'm logged into my Portal via Pro by doing.

 

 

Electric_feat = "https://poralurl/layername/FeatureServer/100"
#Login into Portal
pgis = GIS(portal_url, portal_user, portal_password, verify_cert=False)
print ("Connecting to Portal")

#Select Low Voltage and Medium Voltage Meters and Meter Number is Not Null
selection = arcpy.management.SelectLayerByAttribute(Electric_feat, 'NEW_SELECTION','meternum IS NOT NULL', 'NON_INVERT')
print ("Finish Get Electric Selection")

 

 

However,  when I'm logged out of my portal I get the error that it can't access my feature service (Electric_feat)

So I modified the code to the below and get Object: Error in executing Tool on the select tool.

 

 

pgis = GIS(portal_url, portal_user, portal_password, verify_cert=False)
print ("Connecting to Portal")
eflc = pgis.content.search(Electric_feat)
print (Electric_feat)

#Select Low Voltage and Medium Voltage Meters and Meter Number is Not Null
selection = arcpy.management.SelectLayerByAttribute(eflc, 'NEW_SELECTION','meternum IS NOT NULL', 'NON_INVERT')
print ("Finish Get Electric Selection")

 

 

 I also tried eflc = pgis.content.get(Electric_feat) but I get A general expection was raised: No connection adapters were found for 'content/items/url of Electric_feat on the get script line.

Tags (3)
0 Kudos
1 Reply
Joshua-Young
Occasional Contributor III

I have gotten around that issue by creating a profile using the ArcGIS API for Python. I create the profile outside of my script and then reference the profile in my script. Just remember that you have to create the profile under the account that will be running the script otherwise your script will not be able to find the profile.

For example, if you are using Windows and Task Scheduler, the profile has to be created using the account that is executing the task in Task Scheduler.

Here is a link describing how to create and use a profile: https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/#storing-yo...

"Not all those who wander are lost" ~ Tolkien
0 Kudos