【问题标题】:Flask application cannot find gpgFlask 应用程序找不到 gpg
【发布时间】:2016-12-29 12:10:53
【问题描述】:

我正在使用 python-gnupg 在烧瓶应用程序中连接 gpg。该模块与我的应用程序的其余部分一起安装在 virtualenv 中。运行时收到 500 内部服务器错误,异常是:

File "./myproject/views/settings.py", line 257, in settings_keys_add
    gpg = gnupg.GPG()
File "/home/puse/myproject/myproject/lib/python3.5/site-packages/gnupg.py", line 733, in __init__
    p = self._open_subprocess(["--version"])
File "/home/puse/myproject/myproject/lib/python3.5/site-packages/gnupg.py", line 786, in _open_subprocess
    startupinfo=si)
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'gpg'

gpg 已安装并正在运行:

puse@puse ~/puse> which gpg
/usr/bin/gpg
puse@puse ~/puse> gpg --gen-key 
gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 
gpg: Interrupt caught ... exiting

我也可以让它在 virtualenv 中的 python 中工作:

Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnupg
>>> gpg = gnupg.GPG()
>>> a = gpg.scan_keys("/opt/keys/2a798434-ebb3-4dc6-9f76-fd46f0cce6fa")

我怀疑这与应用程序在哪个用户下运行有关,但应用程序在我的用户下运行,但组设置为 www-data。我已经通过运行 ps 确认了这一点。

应用程序的 systemd .service 文件。

[Unit]
Description=uWSGI instance to serve myproject
After=network.target

[Service]
User=puse
Group=www-data
WorkingDirectory=/home/path
Environment="PATH=/home/path"
ExecStart=/home/path/uwsgi --ini config.ini

[Install]
WantedBy=multi-user.target

【问题讨论】:

    标签: python nginx flask gnupg ubuntu-server


    【解决方案1】:

    您使用此行覆盖(而不是附加到)PATH 变量:

    Environment="PATH=/home/path"
    

    改成

    Environment="PATH=/home/path:/usr/bin:/bin"
    

    能够使用标准命令。

    顺便检查 /home/path 是否存在,我想不存在,在这种情况下只需设置:

    Environment="PATH=/usr/bin:/bin"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      相关资源
      最近更新 更多