How to set the GnuPG home directory within the GnuPG Python binding?

前端 未结 4 1823
悲&欢浪女
悲&欢浪女 2021-01-02 22:59

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

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


        
4条回答
  •  無奈伤痛
    2021-01-02 23:31

    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)
    

    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:

    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 "", line 1, in 
    TypeError: __init__() got an unexpected keyword argument 'gnupghome'
    

    global:

    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 "", line 1, in 
    TypeError: __init__() got an unexpected keyword argument 'homedir'
    

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

提交回复
热议问题