This is a reposted question from raspberrypi.stackexchange.com. While I am trying to get something to work on python on the raspberry pi, since it doesn't involve any pi-specific things, it was suggested by someone I post here instead. Original post is here.
I am trying to make a web ui to change the date in the rapsberry pi, but I keep getting a return code of 256.
Currently what I have goes like this:
web page -> submits an ajax request to a python script python checks what type of command (a time/date command in this case) and pieces together a string looking like:
sudo date --set="20130901 20:10"
and stores it in a variable commandString
. Then python goes:
os.system(commandString)
and the return value is passed all the way up to the web ui where it is printed out.
I also currently return the commandString
value to the web ui too to verify it and it looks okay.
The problem is that every time I test, I keep getting back 256 as the error return code. The date on the raspberry pi of course doesn't change as I manually check it before and after.
However, if I manually go in to python on the raspberry pi and try:
commandString = 'sudo date --set="20130901 20:10"'
os.system(commandString)
It works with no issues. If I try it without sudo
then I get a return value of 256 as well, so I thought maybe it was a permissions issue with my original script. I tried this link to check my script's permissions and it seems to be okay? (os.geteuid()
is 0)
If it matters, I am using lighttpd and fastcgi to run python from a web ui. My lighttpd config is currently:
fastcgi.server = (
".py" => (
"python-fcgi" => (
"socket" => "/tmp/fastcgi.python.socket",
"bin-path" => "/var/www/command.py",
"check-local" => "disable",
"max-procs" => 1)
)
)
Any ideas on what I'm missing?
On the original post, it was also suggested I try something like:
echo <password> | sudo -S date --set="20130829 02:02
While it's probably not a good idea to put in my root password like that, I tried it and got the same result: it works when doing in the terminal/shell and within the python interpreter, but not via the web ui to python.