Pythonは特権降下でルート実行されるスクリプトからFirefoxのウェブブラウザを実行に失敗します
質問
私は、通常のユーザーに権限を落とし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
私は、Pythonの問題ではないと思うが、Firefoxの/のiceweasel / Debianの構成の問題。たぶん、Firefoxは唯一のUIDとないEUIDを読んで、UIDはあなたがについてどう思います0等しいので、プロセスを実行しないのですか?
解決
これは、お使いの環境である可能性があります。アクセス権を変更すると、まだアクセスできなくなりますrootユーザーのディレクトリでの$ HOMEのポインティング、などの環境変数を残します。これは、ブラウザを起動する前にos.environ
を変更することで、これらの変数を変更しようとする価値があるかもしれません。また、チェックする価値、他の変数がある場合があります。
所属していません StackOverflow