如何在GnuPG Python绑定中设置GnuPG主目录? [英] How to set the GnuPG home directory within the GnuPG Python binding?

查看:124
本文介绍了如何在GnuPG Python绑定中设置GnuPG主目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Python中初始化GnuPG绑定时,出现错误消息

When trying to initialize the GnuPG binding in Python, I'm getting an error message

TypeError: __init__() got an unexpected keyword argument 'gnupghome'

这是我正在运行的代码:

This is the code I'm running:

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

我在做什么错了?

推荐答案

在文档方面有不同的网络资源,有些使用homedir,有些使用gnupghome.我不知道他们何时更改它或为什么更改它. 一些简单的代码可以为OP提供解决方案:

There are differnet sources when it comes to documentation, some with homedir, some with gnupghome. I dont know the time they changed it or why. Some trivial code to provide a solution to OP:

import gnupg
print gnupg.__version__
try:
    gpg = gnupg.GPG(gnupghome=homedir) 
except TypeError:
    gpg = gnupg.GPG(homedir=homedir)

请比较以下两个回溯.在两种情况下,其代码相同.在一种情况下,gnupg.GPG预期为"homedir",而在另一种情况下为"gnupghome". 我正在virtualenv中工作,并且有gnupg的两种不同发行版. 在virtualenv中,通过pip安装了python gnupg:

Please compare the two following tracebacks. Its the same code in both cases. In one case gnupg.GPG expects 'homedir and in the other case 'gnupghome'. I am working in a virtualenv and have two different distributions of gnupg. In the virtualenv python gnupg was installed via pip:

virtualenv:

virtualenv:

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版本感到担心.有人可以详细说明此事吗?

I am concerned by the old gnupg version in jessie, though. Can someone elaborate on the matter?

这篇关于如何在GnuPG Python绑定中设置GnuPG主目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆