Search code examples
pythongnupgpgp

Using the Python gnupg package, I am getting the error "Homedir ''C:/Users/...' needs read/write permissions"


I am running Windows 7 with Python version 3.6.1 in Anaconda. I installed the python package gnupg, using pip install gnupg.

I downloaded the gnupg Windows executable 2.1.23 from ftp://ftp.gnupg.org/gcrypt/binary/.

When I run the code with either of the two lines below it fails with the following error.

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')

However when I run the Python code with either of the two lines it fails.

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

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\gnupg\_meta.py in _homedir_setter(self, directory)
    434                 assert _util._has_readwrite(hd), \
--> 435                     "Homedir '%s' needs read/write permissions" % hd
    436             except AssertionError as ae:

AssertionError: Homedir ''C:/Users/Alex/Desktop/SFTP Connection'' needs read/write permissions

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-4-ae272cb064fb> in <module>()
      1 gpg = gnupg.GPG(binary='C:/Program Files (x86)/GnuPG/bin/gpg.exe',
----> 2                homedir='C:/Users/Alex/Desktop/SFTP Connection')

C:\ProgramData\Anaconda3\lib\site-packages\gnupg\gnupg.py in __init__(self, binary, homedir, verbose, use_agent, keyring, secring, ignore_homedir_permissions, options)
    123             verbose=verbose,
    124             use_agent=use_agent,
--> 125             ignore_homedir_permissions=ignore_homedir_permissions,
    126         )
    127 

C:\ProgramData\Anaconda3\lib\site-packages\gnupg\_meta.py in __init__(self, binary, home, keyring, secring, use_agent, default_preference_list, ignore_homedir_permissions, verbose, options)
    181         self.ignore_homedir_permissions = ignore_homedir_permissions
    182         self.binary  = _util._find_binary(binary)
--> 183         self.homedir = os.path.expanduser(home) if home else _util._conf
    184         pub = _parsers._fix_unsafe(keyring) if keyring else 'pubring.gpg'
    185         sec = _parsers._fix_unsafe(secring) if secring else 'secring.gpg'

C:\ProgramData\Anaconda3\lib\site-packages\gnupg\_util.py in __set__(self, obj, value)
    763             self.fset(obj, value)
    764         else:
--> 765             getattr(obj, self.fset.__name__)(value)
    766 
    767     def __delete__(self, obj):

C:\ProgramData\Anaconda3\lib\site-packages\gnupg\_meta.py in _homedir_setter(self, directory)
    438                 log.debug("GPGBase.homedir.setter(): %s" % msg)
    439                 log.debug(str(ae))
--> 440                 raise RuntimeError(str(ae))
    441             else:
    442                 log.info("Setting homedir to '%s'" % hd)

RuntimeError: Homedir ''C:/Users/Alex/Desktop/SFTP Connection'' needs read/write permissions

I've ran the following two commands and verified the folder has read and write access.

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

Solution

  • With regards to the new permissions error, I guess it is actually a bug of gnupg, I have submitted a patch.