How to add credentials in arcgis.features.FeatureLayer

2007
6
02-23-2021 05:14 AM
by Anonymous User
Not applicable

Hello,
I want to query a feature layer on the standalone ArcGIS Server.
arcgis.features.FeatureLayer method does not ask for credentials.

Is there any other method/alternative to use credentials while querying a feature layer?

 

6 Replies
JakeSkinner
Esri Esteemed Contributor

You could do something like below:

 

import requests, json

# Variables
server = 'ags.esri.com'
webAdaptor = 'server'
username = 'siteadmin'
password = '******'
featureService = 'https://ags.esri.com/server/rest/services/WellPads/FeatureServer/0/query'

# Generate Token
tokenURL = 'http://' + server + '/' + webAdaptor + '/admin/generateToken'
params = {'username': username, 'password': password, 'client': 'requestip', 'f': 'pjson'}
response = requests.post(tokenURL, data = params, verify = False)
token = response.json()['token']

# Query Feature Service
whereClause = '1=1'
params = {'where': whereClause, 'outFields': '*', 'token': token, 'f': 'json'}
response = requests.post(featureService, data = params, verify = False)
data = response.json()
0 Kudos
by Anonymous User
Not applicable

Thank you for this code snippet. However, I'm looking for a solution using ArcGIS API for Python classes. I do not have ArcGIS Enterprise, so I cannot use the gis class (arcgis.gis). As I mentioned earlier, I'm working with a standalone ArcGIS Server that is secured using token-based authentication.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Are you using ArcGIS API for Python bundled with Pro or running/using it outside of Pro?  I ask because the ArcGIS API for Python team hosed the stand-alone functionality with changes they made at 1.8.0, and they haven't fixed the issues as of 1.8.4.  If you are using the API bundled with Pro, then you are stuck because you can't change the version.  If you are running the API in Anaconda or outside of Pro and can downgrade to 10.7.x, I can provide some code samples.

0 Kudos
by Anonymous User
Not applicable

Thanks Joshua. I'm using ArcGIS API for Python in Anaconda and outside of pro and I can downgrade to 10.7.x.

0 Kudos
by Anonymous User
Not applicable

Hi Joshua, I downgraded the ArcGIS API for Python to version 1.7.1 as you suggested. However, I'm facing the same issue and I'm unable to pass credentials using the FeatureLayer class. Can you please share some code samples? Thank you

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Are you connecting directly to GIS Server or through a Web Adaptor?  If the latter, does the WA allow admin access or not?

0 Kudos