简体   繁体   English

通过Web服务器调用函数时为什么不执行函数?

[英]Why does function not get executed when called through web server?

There is a python script: 有一个python脚本:

#!/usr/bin/env python
import sys
import subprocess

subprocess.call("sudo /var/www/scripts/setPwm "+ sys.argv[1],shell=True)
print ("Content-type: text/plain;charset=utf-8\n\n")
print("sudo /var/www/scripts/setPwm "+ sys.argv[1])
print("ok\n")

When run locally it lights up a LED with specified intensity. 在本地运行时,它会以指定的强度点亮一个LED。 When called through a website it prints all correctly, but the LED does not light up. 通过网站调用时,它可以正确打印所有内容,但是LED不会点亮。

When I call 当我打电话

http://sauna/scripts/setLED.py?1000

this is printed: 这是打印:

sudo /var/www/scripts/setPwm 1000
ok

so the argument is apparently passed correctly, there are also no errors in apache log. 因此参数显然已正确传递,apache日志中也没有错误。 Still there is no light :( 仍然没有光:(

问题是,apache服务器与我的用户( www-data )是不同的用户。将用户( www-data )添加到/etc/sudoers以获取需要以root用户身份运行的特定可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Web服务器执行时,为什么Python环境变量不同? - Why are Python environment variables different when executed from a web server? 通过我的个人服务器使用 python 调用 web 抓取时出错 - Error when web scraping is called through my personal server with python 何时调用/引用函数以及何时执行? - When is a function called/referred to and when is it being executed? execute() function 调用时未执行 - execute() function is not being executed when called 在python中,为什么只有在调用另一个模块的方法时才会执行类体中的代码? - In python,why does the code in class body gets executed only when a method of another module is called? 为什么django向导表单通过get_form function传一个表单不提交? - Why does django wizard form not submit when one form is passed through get_form function? 如果不调用 function,为什么从 function 执行打印语句? - Why the print statement is being executed from the function if the function is not called? 为什么在调用exec()时出现语法错误? - Why does this get a syntax error when exec() is called? 为什么课程在未启动时会被“调用”? - Python - Why does a class get “called” when not initiated? - Python 为什么if块在其他地方之后执行? - Why does the if block get executed after else?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM