Select to view content in your preferred language

Using Python API to create and query a restricted and unfederated feature service

981
1
06-18-2020 10:39 AM
Jay_Gregory
Frequent Contributor

I'm aware of how to use the Python API to authenticate to a GIS and then create a FeatureLayer from a feature service to query or extract data from.  

However, I can't seem to figure out how to do the same when there is no underlying Portal.  

The feature service in question is restricted, but I am able to login and traverse the REST endpoints from my browser.  Similarly, I can (using Python) generate a token from the Server's generateToken endpoint.  However, since the server is not federated, I am not able to use the Python API to get access to the underlying feature services:

For my example: say my REST endpoints are at: https://myserver.domain.com/restricted/rest/services

Example code:

gis = GIS("https://myserver.domain.com/restricted", username=username, password=password) - generates an error

fl = arcgis.features.FeatureLayer("https://myserver.domain.com/restricted/rest/services/myservice/0").query() - also generates an error.  

I have tried generating a token and then passing it in to both the Feature layer or the GIS and nothing seems to work.  Is there any workaround here I'm missing?

Thanks!

0 Kudos
1 Reply
Jay_Gregory
Frequent Contributor

Nevermind - just realized there is a arcgis.gis.server module that solves my issue.  Figured it out.  

gis = arcgis.gis.server.Server("https://myserver.domain.com/restricted/admin", username=username, password=password)

fl = arcgis.features.FeatureLayer(featurelayerurl, gis=gis).query()

0 Kudos