On Tue, 23 Jun 2020 00:40:28 +0100, MRAB <pyt...@mrabarnett.plus.com> wrote:
> On 2020-06-22 23:38, Seb wrote: >> Hello, >> What's the pythonic way to do this without polluting the user's >> directory with the decrypted file? I wrongly thought this should do >> it: >> import os.path as osp import gnupg import netrc import tempfile >> gpg = gnupg.GPG() >> with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: with >> tempfile.NamedTemporaryFile("w+") as tf: status = gpg.decrypt_file(f, >> output=tf.name) info = netrc.netrc(tf.name) >> which fails as the temporary file doesn't even get created. > Are you sure it doesn't get created? Without using tempfile: with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: status = gpg.decrypt_file(f, output=".authinfo.txt") info = netrc.netrc(".authinfo.txt") I get the error: NetrcParseError: bad follower token 'port' (.authinfo.txt, line 1) which is interesting. The structure of ~/.authinfo.gpg is: machine my.server.com login u...@foo.com password mypasswd port 587 so it seems this is not what netrc.netrc expects. -- Seb -- https://mail.python.org/mailman/listinfo/python-list