使用pythongnupg包,我得到错误“Homedir''C:/Users/…'需要读/写权限”

2024-05-17 05:28:55 发布

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

我在Anaconda运行Windows7和Python3.6.1版本。我使用pip install gnupg安装了python包gnupg。在

我从ftp://ftp.gnupg.org/gcrypt/binary/下载了gnupgwindows可执行文件2.1.23。在

当我用下面两行中的任何一行运行代码时,它将失败,并出现以下错误。在

import gnupg

gpg = gnupg.GPG(binary='C:/Program Files (x86)/GnuPG/bin/gpg.exe',
               homedir='C:/Users/Alex/Desktop/SFTP Connection')

# gpg = gnupg.GPG(binary='C:/Program Files (x86)/GnuPG/bin/gpg.exe')

但是,当我用这两行代码中的任何一行运行Python代码时,它都会失败。在

^{pr2}$

我运行了以下两个命令,并验证了文件夹具有读写访问权限。在

>>> os.access('C:/Users/Alex/Desktop/SFTP Connection', os.W_OK)
True
>>> os.access('C:/Users/Alex/Desktop/SFTP Connection', os.R_OK)
True
>>>

Tags: 代码osftpfilesconnectionprogramgpgusers
2条回答

GnuPG主目录是GnuPG存储其密钥环和信息的地方。不能使用此配置变量来确定Python模块在何处搜索二进制文件。事实上,这个never应该设置为二进制文件的存储位置(无论如何也不应该在程序文件目录中)。在

相反,请将目录添加到%PATH环境变量或使用^{}变量,该变量应包含二进制文件的绝对路径:

gpg = gnupg.GPG(binary='C:/Program Files (x86)/GnuPG/bin/gpg.exe')

Python module's documentation

binary (str) – Name for GnuPG binary executable. If the absolute path is not given, the environment variable $PATH is searched for the executable and checked that the real uid/gid of the user has sufficient permissions.

homedir (str) – Full pathname to directory containing the public and private keyrings. Default is whatever GnuPG defaults to.

关于新权限错误,我想这实际上是gnupg的一个bug,Ihave submitted a patch。在

相关问题 更多 >