'GNUPG Decryption fails with error as : gpg: [don't know]: partial length for invalid packet type 20

There is a requirement to decrypt a file which is GNU Privacy Guard(GPG) encrypted. I have the private key(.asc file), which can be used for decryption purpose. The name of the file which is to be decrypted is - my_file_name.txt.gpg Expected output file - my_file_name.txt

The python code snippet I am using is as below:

import gnupg

gpg = gnupg.GPG()
key_to_import = '<<.asc file path>>'
key_data = open(key_to_import).read()
import_result = gpg.import_keys(key_data)

with open('<<.gpg file path which is to be decrypted>>', 'rb') as f:
     status = gpg.decrypt_file(f,always_trust=True,output='<<output-decrypted-file-path>>')
     print(status.ok)
     print(status.stderr)

The above piece of code works correctly on my local machine(Windows-10). However, when same code is executed from an AWS ec2 instance, which has LINUX OS(Not Ubuntu) with .gpg and .asc file also present on same ec2 instance, there is a failure with error message as -gpg: [don't know]: partial length for invalid packet type 20

I am unable to understand what went wrong here.

gpg version on windows PC - 2.3.6
gpg version on ec2-instance - 2.0.22-5.amzn2.0.4


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source