How to set GnuPG home directory in Python GnuPG bundle?

When I try to initialize a GnuPG binding in Python, I get an error

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 

What am I doing wrong here?

+6
source share
4 answers

You should refer to the gnupg documentation as it uses homedir in the gnupghome location.

Please follow the documentation that may solve your problems: python gnupg documentation

+2
source

There are differnet sources when it comes to documentation, some with homedir, some with gnupghome. I don’t know how they changed it or why. Some trivial code to solve OP:

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

Please compare the following two traces. This is the same code in both cases. In one case, gnupg.GPG expects "homedir", and in the other case "gnupghome". I work in virtualenv and have two different gnupg distributions. In virtual 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: __init__() got an unexpected keyword argument 'homedir' 

I am worried about the old version of gnupg in jessie. Can anyone sort this out?

+2
source

GnuPG (as a command line tool) knows two ways to specify the GnuPG home directory:

  • Using an environment variable:

     GPGHOME=C:\Users\samss\AppData\Roaming\gnupg gpg 
  • Passing it as a parameter (which is also available as the homedir parameter in the configuration file):

     gpg --homedir=C:\Users\samss\AppData\Roaming\gnupg 

GnuPG Python binding allows you to pass some parameters during initialization. Due to the initialization syntax, you probably mixed this with an environment variable that defines the home directory on the command line.

Additional warning. You probably want to access the GnuPG home directory of another system user. GnuPG is very picky about secure permissions. It would be nice for the development machine to use the GnuPG parameter --no-permission-warning and privileges that allow fairly wide access, but it is better to start with a clean approach from the very beginning and initialize the new GnuPG home directory for your application, which may be correctly limited with respect to permissions .

0
source

There are at least 3 different versions of the python gnupg module. At least 2 of them are in pips.

If you run pip install gnupg , you will get an older module that uses the homedir argument.

If you run pip install python-gnupg you will get a newer module. In this case, it was the documentation for the module that you read.

0
source

Source: https://habr.com/ru/post/1241572/


All Articles