我有一个使用nginx服务的uWSGI下的python flask应用程序。 python代码调用subprocess.Popen()
来运行浏览器(即Firefox,Chrome),但uWSGI日志显示错误。 错误与linux(ubuntu)标准命令有关,即readlink
,which
,cat
等。uWSGI python subprocess chrome/firefox失败
我怀疑这是用户访问相关,但不确定。 uWSGI服务使用我的用户和www-data
组运行。
Python代码
import subprocess
@app.route('/api/check/version', methods=['POST'])
def check_version():
pid = subprocess.Popen(['/usr/bin/firefox', '--version'], stdout=subprocess.PIPE)
#pid = subprocess.Popen(['/usr/bin/google-chrome', '--version'], stdout=subprocess.PIPE)
data = pid.communicate()
return data
if __name__ == "__main__":
check_version()
uWSGI日志
**in case of doing Popen for /usr/bin/firefox
/usr/bin/firefox: 1: /usr/bin/firefox: which: not found
**in case of doing Popen for /usr/bin/google-chrome
/usr/bin/google-chrome-stable: line 8: readlink: command not found
/usr/bin/google-chrome-stable: line 10: dirname: command not found
/usr/bin/google-chrome-stable: line 46: exec: cat: not found
/usr/bin/google-chrome-stable: line 45: exec: cat: not found
uWSGI服务配置
[Unit]
Description=uWSGI instance to serve myproject
After=network.target
[Service]
User=myuser
Group=www-data
WorkingDirectory=/home/gbadmin/myproject
Environment="PATH=/home/gbadmin/myproject/myprojectenv/bin"
ExecStart=/home/gbadmin/myproject/myprojectenv/bin/uwsgi --ini myproject.ini
[Install]
WantedBy=multi-user.target
感谢您的快速明确的答复,这解决了这个问题。 – Hussain