Search code examples
pythonfilepostencryptiongnupg

How can I encrypt files from request post with gpg


Is possible encrypt files from request post? How?

files = request.FILES[files]
gpg = gnupg.GPG(homedir='/home/XXXX/.gnupg')
gpg.encrypt(files) <-- This do exception

Exception:

'InMemoryUploadedFile' object has no attribute 'encode'


Solution

  • As said by the documentation you should pass a string to encrypt(), not a file. encrypt() is certainly trying to get the encoded string by trying to call .encode() on the argument.

    You can find an example of encrypting a file here.