用Djang运行脚本

2024-06-01 08:21:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用Django运行一个脚本。这个脚本需要与sudo一起运行,我已经设置了sudoers文件,这样就可以在不输入sudo密码的情况下执行命令。当我使用默认测试服务器时,即python管理.py运行服务器0.0.0.0:8000,脚本执行没有问题。但是,在使用Nginx和uWSGI部署Django之后,命令将失败并返回响应

sudo: no tty present and no askpass program specified

有什么配置我错过了吗?在

我使用subprocess来执行脚本,Django视图中的代码如下:

^{pr2}$

Tags: 文件djangonopy服务器脚本密码部署
1条回答
网友
1楼 · 发布于 2024-06-01 08:21:27

您需要将正在使用的用户添加到sudoers列表中:

Granting the user to use that command without prompting for password should resolve the problem. First open a shell console and type:

sudo visudo

Then edit that file to add to the very end:

username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand

eg

john ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop

will allow user 'john' to sudo poweroff, start and stop without being prompted for password.

Look at the bottom of the screen for the keystrokes you need to use in visudo - this is not vi by the way - and exit without saving at the first sign of any problem. Health warning: corrupting this file will have serious consequences, edit with care!

来源:How to fix 'sudo: no tty present and no askpass program specified' error?

相关问题 更多 >