Browse Source

try encrypt again if fail

Son NK 5 years ago
parent
commit
c8cd066d25
1 changed files with 10 additions and 7 deletions
  1. 10 7
      app/pgp_utils.py

+ 10 - 7
app/pgp_utils.py

@@ -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
-        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")
+        LOG.error("Try encrypt again %s", fingerprint)
+        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)
     return str(r)