尝试在Python语言中初始化GnuPG绑定时,收到一条错误消息
TypeError: __init__() got an unexpected keyword argument 'gnupghome'这是我正在运行的代码:
import gnupg
gpg = gnupg.GPG(gnupghome='C:\Users\samss\AppData\Roaming\gnupg')
input_data = gpg.gen_key_input(key_type="RSA",
key_length=1024,
passphrase='n0sm@sy0')
key =gpg.gen_key(input_data)
print key我在这里做错了什么?
发布于 2016-02-05 18:56:52
当涉及到文档时,有不同的来源,一些是homedir,一些是gnupghome。我不知道他们什么时候改的,也不知道为什么。一些简单的代码来为OP提供解决方案:
import gnupg
print gnupg.__version__
try:
gpg = gnupg.GPG(gnupghome=homedir)
except TypeError:
gpg = gnupg.GPG(homedir=homedir)请比较以下两个回溯。这两种情况的代码都是相同的。在一种情况下,gnupg.GPG需要'homedir‘,在另一种情况下,需要'gnupghome’。我在一个虚拟环境中工作,有两个不同的gnupg发行版。在virtualenv中,python gnupg是通过pip安装的:
虚拟环境:
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnupg
>>> gnupg.__version__
'2.0.2'
>>> homedir=''
>>> gpg = gnupg.GPG(homedir=homedir)
>>> gpg = gnupg.GPG(gnupghome=homedir)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'gnupghome'全局:
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnupg
>>> gnupg.__version__
'0.3.6'
>>> homedir=''
>>> gpg = gnupg.GPG(gnupghome=homedir)
>>> gpg = gnupg.GPG(homedir=homedir)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'homedir'不过,我对jessie中的旧gnupg版本感到担忧。有人能详细说明一下这件事吗?
发布于 2016-01-27 13:17:26
您应该参考gnupg文档,因为它使用homedir而不是gnupghome。
请遵循它可能解决您的问题的文档:gnupg python documentation
发布于 2019-07-04 05:20:24
python gnupg模块至少有3个不同的版本。其中至少有2个是pip格式的。
如果使用pip install gnupg,就会得到使用homedir参数的较旧的模块。
如果你使用pip install python-gnupg,你会得到一个更新的模块。在本例中,它是您正在阅读的模块的文档。
https://stackoverflow.com/questions/35028852
复制相似问题