Using version 1.7.0 of the API, this code snippet works fine:
from arcgis.gis import server
user = '<admin user>'
pswd = '<password>'
server_base_url = "https://<server>/<webadaptor>"
gis_server = server.Server(url=f"{server_base_url}/admin",
token_url=f"{server_base_url}/tokens/generateToken",
username=user,
password=pswd)service = gis_server.content.get('<Service Name>', folder='<Service Folder>')
service.service.status
{'configuredState': 'STARTED', 'realTimeState': 'STARTED'}
However, in 1.8.2 the service status returns:
{'status': 'error', 'messages': ["Unauthorized access. Token not found. You can generate a token using the 'generateToken' operation."], 'code': 499}
It actually broke in 1.8.0, but remains broken through 1.8.2. What you are seeing is related to a defect I reported to the team last week, and they have stated it will be addressed in 1.8.3. See arcgis.gis.server.admin.administration.Server Mangles arcgis.gis._impl._con._connection.Connection ·...
Thanks for the reply and link to your open Issue on their Github site. I didn't notice it when I entered my issue today (Stand-Alone ArcGIS Server Authentication Fails · Issue #752 · Esri/arcgis-python-api · GitHub )
We finally have access to this API in the enterprise environment I support and I seem to keep tripping over these issues. Really hard not to give up and stick with the tried and true REST API.
I hear ya. The ArcGIS API for Python is mostly a wrapper for the REST API, but there are things the team implements differently than how I interact with the REST API directly, so there are some trade-offs using it.