我试图通过Win7上的Python脚本使用GnuPG解密tar文件。
filename_e_archive = askopenfilename()
current_directory = os.path.abspath('.')
folder_d_archive = filename_e_archive.split('.elog')[0]
filename_d_archive = folder_d_archive + ".tar.gz"
path_to_e_archive = os.path.dirname(filename_e_archive)
path_to_d_archive = os.path.join(path_to_e_archive,'/',folder_d_archive)
os.makedirs(path_to_d_archive)
os.chdir(path_to_d_archive)
gpg = gnupg.GPG()
with open(filename_e_archive, 'rb') as f:
status = gpg.decrypt_file(f, passphrase='mypassword',output=filename_d_archive)
运行时我收到以下错误:
C:\ LA> python test.py Traceback(最近一次调用最后一次):文件“test.py”,第30行,在gpg = gnupg.GPG()文件“C:\ Python27 \ lib \ site-packages \ gnupg \ gnupg.py“,第125行,在init ignore_homedir_permissions = ignore_homedir_permissions,文件”C:\ Python27 \ lib \ site-packages \ gnupg_meta.py“,第183行,在init self.homedir = os.path.expanduser(home)中home else _util._conf文件“C:\ Python27 \ lib \ site-packages \ gnupg_util.py”,第765行,在set getattr(obj,self.fset.name)(value)文件“C:\ Python27 \ lib \ site-packages \ gnupg_meta.py“,第440行,在_homedir_set中引发RuntimeError(str(ae))RuntimeError:Homedir''C:\ LA \ gnupghome.config \ python-gnupg''需要读/写权限
C:\ TO>
我能够通过删除gnupg库来解决这个问题:
pip卸载gnupg
并安装python-gnupg
pip install python-gnupg