encryption - Python catch specific exceptions -


i have python script being used automate gpg/pgp file encryption (among few other tasks) , i'm having issue catching errors being thrown gunpg within script. overall setup configuring variables in database table , pulling them script encrypt files.

so i'm looking @ catching errors related encryption process failing (such incorrectly typed key in database). when execute encryption, bad key, python shell following error:

<gnupg.crypt object @ 0x7f49d0c51b50> 

i'm attempting catch error , send info log file can better debug issues when setting up. here code script relates this:

try:     gpg.encrypt_file(open_file,pub_key,always_trust=true,output=enc_file) except:     logger.error('error: check keystore and/or public key') 

this gets skipped on , find out later down in script encryption process failed, when attempt validate if encrypted file exists.

any appreciated. thanks!

<gnupg.crypt object @ 0x7f49d0c51b50> return value gpg.encrypt_file(), not exception. python console displaying because didn't assign variable.

note docs encrypt_file() state:

any public key provided encryption should trusted, otherwise encryption fails without warning. this because gpg prints message console, not provide specific error indication python wrapper can use.

presumably, applies in case when key not exist in keystore.


Comments