try encrypt again if fail

This commit is contained in:
Son NK 2020-06-06 23:06:34 +02:00
parent e5b60d9251
commit c8cd066d25

View file

@ -26,12 +26,15 @@ def load_public_key(public_key: str) -> str:
def encrypt_file(data: BytesIO, fingerprint: str) -> str: def encrypt_file(data: BytesIO, fingerprint: str) -> str:
r = gpg.encrypt_file(data, fingerprint, always_trust=True) r = gpg.encrypt_file(data, fingerprint, always_trust=True)
if not r.ok: if not r.ok:
# save the content for debugging LOG.error("Try encrypt again %s", fingerprint)
random_file_name = random_string(20) + ".eml" r = gpg.encrypt_file(data, fingerprint, always_trust=True)
full_path = f"/tmp/{random_file_name}" if not r.ok:
with open(full_path, "wb") as f: # save the content for debugging
f.write(data.getbuffer()) random_file_name = random_string(20) + ".eml"
LOG.error("Log to %s", full_path) full_path = f"/tmp/{random_file_name}"
raise PGPException("Cannot encrypt") with open(full_path, "wb") as f:
f.write(data.getbuffer())
LOG.error("Log to %s", full_path)
raise PGPException("Cannot encrypt")
return str(r) return str(r)