From 9603683c18bc15fe459c222fd6a257c23c15e27c Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Fri, 5 Jun 2020 10:10:21 +0200 Subject: [PATCH] log the failed encrypted content to debug --- app/pgp_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/pgp_utils.py b/app/pgp_utils.py index 73bafb01..dd5fd4b4 100644 --- a/app/pgp_utils.py +++ b/app/pgp_utils.py @@ -3,6 +3,8 @@ from io import BytesIO import gnupg from app.config import GNUPGHOME +from app.log import LOG +from app.utils import random_string gpg = gnupg.GPG(gnupghome=GNUPGHOME) gpg.encoding = "utf-8" @@ -24,6 +26,12 @@ def load_public_key(public_key: str) -> str: def encrypt_file(data: BytesIO, fingerprint: str) -> str: r = gpg.encrypt_file(data, fingerprint, always_trust=True) if not r.ok: + # save the content for debugging + random_file_name = random_string(20) + ".eml" + full_path = f"/tmp/{random_file_name}" + 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)