蟒蛇无法从根执行脚本的权限执行降火狐网页浏览器
题
我不能从滴特权普通用户一个sudoed Python脚本运行的Firefox。如果我写
$ sudo python >>> import os >>> import pwd, grp >>> uid = pwd.getpwnam('norby')[2] >>> gid = grp.getgrnam('norby')[2] >>> os.setegid(gid) >>> os.seteuid(uid) >>> import webbrowser >>> webbrowser.get('firefox').open('www.google.it') True >>> # It returns true but doesn't work >>> from subprocess import Popen,PIPE >>> p = Popen('firefox www.google.it', shell=True,stdout=PIPE,stderr=PIPE) >>> # Doesn't execute the command >>> You shouldn't really run Iceweasel through sudo WITHOUT the -H option. Continuing as if you used the -H option. No protocol specified Error: cannot open display: :0
我认为不是蟒问题,但Firefox / iceweasel / Debian配置问题。也许Firefox的只读UID和不EUID,因为UID是等于0.你怎么看待不执行过程?
解决方案
这可能是您的环境。更改权限将仍然留在像根用户目录$ HOME指点,这将是无法访问的环境变量。这可能是值得尝试通过启动浏览器之前改变os.environ
改变这些变量。还可以有值得检查其他变量。
不隶属于 StackOverflow