Python 如何使用recipients属性对文件进行gpg加密?
我试图在python中使用recipients属性对文件进行GPG加密,但出现了一个错误Python 如何使用recipients属性对文件进行gpg加密?,python,python-3.x,gnupg,pgp,Python,Python 3.x,Gnupg,Pgp,我试图在python中使用recipients属性对文件进行GPG加密,但出现了一个错误 import os import os.path import time gpg = gnupg.GPG(homedir='/home/ec2-user/.gnupg') path = '/home/ec2-user/pgp' ptfile = '/demo' with open('/home/ec2-user/pgp/demo.txt', 'rb')as f: status = gp
import os
import os.path
import time
gpg = gnupg.GPG(homedir='/home/ec2-user/.gnupg')
path = '/home/ec2-user/pgp'
ptfile = '/demo'
with open('/home/ec2-user/pgp/demo.txt', 'rb')as f:
status = gpg.encrypt(f, recipients='email@domain.com', passphrase='secret')
print(status.ok)
print(status.stderr)
我得到以下错误:
[ec2-user@domain pgp]$ python3 pgp_encrypt.py
Traceback (most recent call last):
File "pgp_encrypt.py", line 12, in <module>
status = gpg.encrypt(f, recipients='email@domain.com', passphrase='secret')
File "/home/ec2-user/.local/lib/python3.8/site-packages/gnupg/gnupg.py", line 1064, in encrypt
result = self._encrypt(stream, recipients, **kwargs)
TypeError: _encrypt() got multiple values for argument 'recipients'
我犯了错误
[ec2-user@domain pgp]$ python3 pgp_encrypt.py
Traceback (most recent call last):
File "pgp_encrypt.py", line 12, in <module>
status = gpg.encrypt_file(f, recipients='email@domain.com', passphrase='secret')
AttributeError: 'GPG' object has no attribute 'encrypt_file'
如何修复代码
[ec2-user@domain pgp]$ python3 pgp_encrypt.py
Traceback (most recent call last):
File "pgp_encrypt.py", line 12, in <module>
status = gpg.encrypt_file(f, recipients='email@domain.com', passphrase='secret')
AttributeError: 'GPG' object has no attribute 'encrypt_file'
status = gpg.encrypt(f, symmetric=True, passphrase='Xcelenergy1!', encrypt=False)