views:

222

answers:

1

Hi folks,

I'm using popen in order to send a few commands within a Django app.

Problem is that I'm getting [Error 5] Access Denied, apparently I have no access to cmd.exe, which popen seems to use.

WindowsError at /test/cmd/

[Error 5] Access is denied: 'C:\WINDOWS\system32\cmd.exe /c dir'

I reckon this is because the app sits behind a web server which has limited privileges.


Is there anything we can do about it? Help would be awesome!

+2  A: 

Why you have the problem:

What you forgot to mention in your question is that you are trying to run it under IIS with ISAPI > ISAPI_WSGI (or FastCGI on IIS 7/6 with flup as FastCGI wrapper for WSGI).

It's truly an execute permission issue on c:\windows\system32\cmd.exe

I had exactly same problem on IIS 6. Played with pool settings, thinking that setting the pool user to "Local System" or something similar would fix it. Regardless of what user I set the pool to, I would always get Access Denied. I foolishly assumed there is something wrong with cPython pipes, cause running commands under IronPython on the same machine worked.

Here is how you fix it:

A.

Relax user permissions on either IIS service or on c:\windows\system32\cmd.exe (Relaxing permissions on application pool, with tight permissions on IIS process did not help me. My guess is that ISAPI > ISAPI_WSGI runs with permissions limited to those of IIS process.)

User running IIS (Web Publishing) service must be added directly, or be in at least one group that has read, execute permissions on c:\windows\system32\cmd.exe

Things I did not try: I wonder if instead of changing user permissions on IIS service, changing the user behind "Anonymous" would work.

B.

If you are serious about making it work on Windows, contemplate ditching cPython for IronPython + NWSGI (look for it on CodePlex) I use NWSGI for simple WSGI apps and CAN run subprocesses with a subprocess.py specifically written for IronPython. (it's here: http://bitbucket.org/jdhardy/code/src/126ce1f8fddd/subprocess.py Check out other repos by same jdhardy. He has some patches specifically to make Django work on .Net, IronPython.)

ddotsenko
@ddotsenko: Thanks for your more than awesome reply! Wish I could vote on this more than once. I'm pretty much screwed by the sound of it, as I have only access to the Django app code for the time being. I have no access to the Server in any way at the moment. All I need to do is run a script that would enable me to restart IIS. Someone mentioned [this python library](http://timgolden.me.uk/python/wmi/), but I am not 100% sure it will work.
RadiantHex
@RadiantHex :) Turns out was wrong and confused about the cause of the issue. Had the issue fixed in my case. Updated the response. Apologies for original misleading reply.
ddotsenko
@ddotsenko: thank you so much! I would have left the old reply in, as I believe it would have been incredibly useful for people having similar problems. There is not much info about IIS6-Django setups around, and you have given the information I really needed! Thanks indeed!
RadiantHex