python gnupg.GPG no such file or directory -
i'm trying verify file signature, when creating gnupg object using
gpg = gnugp.gpg(gnupghome='/users/myname/.gnupg')
however keep getting no such file or directory error. i've tried different paths home, not including path , letting use default, no avail.
some of functions not need beyond gpg home directory (i.e. ~/.gnupg) specified, others require little more that. if you're manipulating keyrings.
i got around making config.py file in same directory other scripts contains this:
homedir = "/users/username" gpg_home = homedir+"/.gnupg" gpg_homeshort = "~/.gnupg" # optional pub_ring = gpg_home+"/pubring.gpg" sec_ring = gpg_home+"/secring.gpg" pring = [] sring = [] pring.append(pub_ring) sring.append(sec_ring)
that's os x, linux, bsd , other unixes change first line to:
homedir = "/home/username"
for scripts basic encryption , decryption, should work:
import gnupg config import * gpg = gnupg.gpg(gnupghome=gpg_home)
with verbose parameter results in:
>>> gpg = gnupg.gpg(gnupghome=gpg_home, verbose=true) gpg --status-fd 2 --no-tty --homedir /users/username/.gnupg --version >>>
the shorter form results in:
>>> gpg = gnupg.gpg(gnupghome=gpg_homeshort, verbose=true) gpg --status-fd 2 --no-tty --homedir '~/.gnupg' --version >>>
for scripts search through default keyrings, should work:
import gnupg config import * gpg = gnupg.gpg(gnupghome=gpg_home, keyring=pring, secret_keyring=sring) gpg.encoding = "latin-1" pkeys = gpg.list_keys(false) skeys = gpg.list_keys(true)
note change of character encoding, prevent errors when reading keyrings may contain strange keys (which may or may not break scripts if leave "utf-8"). result in pkeys , skeys being created lists each entry containing dict each key in keyring.
the verbose form results in:
>>> gpg = gnupg.gpg(gnupghome=gpg_home, keyring=pring, secret_keyring=sring, verbose=true) gpg --status-fd 2 --no-tty --homedir /users/username/.gnupg --no-default-keyring --keyring /users/username/.gnupg/pubring.gpg --secret-keyring /users/username/.gnupg/secring.gpg --version >>>
the short form results in:
>>> gpg = gnupg.gpg(gnupghome=gpg_homeshort, keyring=pring, verbose=true) gpg --status-fd 2 --no-tty --homedir '~/.gnupg' --no-default-keyring --keyring /users/username/.gnupg/pubring.gpg --version >>>
it quite possible manipulate paths use alternative keyrings or possibly relative paths portable implementation.
anyway, here's nice , quick demonstration keyrings (assuming same config file above):
import gnupg config import * gpg = gnupg.gpg(gnupghome=gpg_home, keyring=pring, secret_keyring=sring) gpg.encoding = "latin-1" pkeys = gpg.list_keys(false) skeys = gpg.list_keys(true) pnum = len(pkeys) snum = len(skeys) print(""" %s contains %d public keys %s contains %d private keys """ % (pub_ring, pnum, sec_ring, snum))
Comments
Post a Comment