aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/examples/howto/decrypt-file.py
diff options
context:
space:
mode:
Diffstat (limited to 'lang/python/examples/howto/decrypt-file.py')
-rwxr-xr-xlang/python/examples/howto/decrypt-file.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lang/python/examples/howto/decrypt-file.py b/lang/python/examples/howto/decrypt-file.py
index 60a050bd..b38acc79 100755
--- a/lang/python/examples/howto/decrypt-file.py
+++ b/lang/python/examples/howto/decrypt-file.py
@@ -38,7 +38,14 @@ else:
newfile = input("Enter path and filename of file to save decrypted data to: ")
with open(ciphertext, "rb") as cfile:
- plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+ try:
+ plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+ except gpg.errors.GPGMEError as e:
+ plaintext = None
+ print(e)
-with open(newfile, "wb") as nfile:
- nfile.write(plaintext)
+if plaintext is not None:
+ with open(newfile, "wb") as nfile:
+ nfile.write(plaintext)
+else:
+ pass