How to script start/stop service, with web-tier authentication?

203
2
09-14-2021 12:16 PM
AllenDailey1
Occasional Contributor

Hello,

I have done lots of searching about this but have not found anything in Esri documentation or here in the Community, so I thought I'd see if anyone can help.

My organization is in the midst of a server migration.  In our old ArcGIS Server environment, we had token authentication, but in the new one, we have web-tier authentication.  I am trying to migrate a Python script that rebuilt an address locator in the old environment; the script includes stopping and then starting services, which is necessary for rebuilding the address locator.  I have 2 main problems:

  1. The first problem is that I have no idea how to write Python for web-tier authentication, instead of tokens. I have researched this but haven't found anything.  Any suggestions?
  2. The second problem is that it sounds like it's not possible to stop/start services via a script anymore, at least not as simply as in the past (see: https://community.esri.com/t5/arcgis-enterprise-questions/start-stop-secure-services-in-10-6-1/td-p/... ). 
    • I saw that it is possible to do it with the ArcGIS API for Python, but that it requires that the server be federated (https://support.esri.com/en/technical-article/000019994 ). 
    • The involved servers are not federated, unfortunately, but we have other servers that are federated. 
    • Does anyone know how to stop/start services in a script, services that are not on a federated server?

Thanks so much!

Allen

0 Kudos
2 Replies
JonathanQuinn
Esri Frequent Contributor

You can use the requests_ntlm library using the HttpNtlmAuth or HttpNegotiateAuth functions. HttpNtlmAuth requires you to pass in a username and password but HttpNegotiateAuth can simulate a single sign on experience. 

https://pypi.org/project/requests_ntlm/0.2.0/
https://github.com/brandond/requests-negotiate-sspi

For services that are not on a federated Server using IWA, once you know what APIs are responsible for stopping/starting services, you can use the requests library; the samples on their help page are pretty useful. For example, use either function above, then use the auth object in the requests.post function:

response = requests.post(url,data=params,auth=auth).text

0 Kudos
AllenDailey1
Occasional Contributor

Thank you, Jonathan!  I appreciate your reply.

I don't really know anything about requests and scripting internet-related things (someone else wrote the scripts that I have to work with), so I don't yet understand what those sources are talking about, but I will keep doing research and learning.  You have given me a helpful starting place, with those links and your reply.  Thank you!!

0 Kudos