Having a problem executing a Python script from a .NET web service.
The web services creates a System.Diagnostics.Process for python.exe and passes a Python script path as an argument.
The web service is running as a custom local account. The python script succeeds if I add the custom local account to the administrators group but I can’t do this as a solution.
The Python script is failing to import a library from ESRI called ArcPy. It looks like this module utilizes a Java JAR to invoke ArcObjects from (ESRI’s API).
It only fails when run in the context of the web service. If I open a cmd shell using runas to run it as the web app pool custom account and call the python script it works fine (even when the app pool account is not in the administrators group). It only requires being in the administrators group when run as the web service.
I’ve looked through procmon for entries from w3wp.exe and python.exe but I haven’t found anything that I need to change permissions for.
I am wondering why it works from a shell running as the app pool account but not from the web service.
I grant every single local user rights assignment policy to the app pool account but it didn’t work so I’ve ruled that out.
I’ve also changed the web service app pool to load the user profile but that didn’t help either.
What’s different about the execution environment when a system.diagnostics.process is run in the context of an IIS app pool vs a shell running as the same account?
It turns out it had nothing to do with security. ESRI installs it’s instance of python and adds .PTH files to the Lib\site-packages directory.
I have both ArcGIS Desktop and ArcGIS server installed and both have the ArcPy python module in there program files directories. Python was importing the wrong module because it was first in the path.
The issue is documented in this ESRI KB.
http://support.esri.com/en/knowledgebase/techarticles/detail/39029
I have no idea why it worked when the account was in the administrators group though.