Describe the bug
When using python-gnupg with Deja Dup / Duplicity (which switched to this library recently in version 3.2.0), passphrases containing non-Latin-1 characters or Unicode symbols fail with: Thread exception: 'latin-1' codec can't encode character '***' in position *: ordinal not in range(256)
This occurs because self.encoding hardcodes latin-1: https://github.com/vsajip/python-gnupg/blob/master/gnupg.py#L1155
The only way to override it is externally on the instance, but it's unclear if that is the intended solution. I noticed an old comment suggesting an external override is expected, but shouldn't it be configurable via constructor arguments?
To Reproduce
import gnupg
gpg = gnupg.GPG()
# Passphrase containing non-Latin-1 / Unicode characters
status = gpg.encrypt("Test payload", recipients=None, symmetric=True, passphrase="błąd")
print(status.status)
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
...
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-2: ordinal not in range(256)
Expected behavior
python-gnupg should gracefully handle utf-8 encoded non-Latin-1 inputs and passphrases without failing on latin-1 encoding limitations.
Screenshots
N/A
Environment
- OS, including version: Arch Linux
- Version of this library: 0.5.6
- Version of GnuPG: gpg (GnuPG) 2.4.9
Additional information
Describe the bug
When using python-gnupg with Deja Dup / Duplicity (which switched to this library recently in version 3.2.0), passphrases containing non-Latin-1 characters or Unicode symbols fail with:
Thread exception: 'latin-1' codec can't encode character '***' in position *: ordinal not in range(256)This occurs because
self.encodinghardcodeslatin-1: https://github.com/vsajip/python-gnupg/blob/master/gnupg.py#L1155The only way to override it is externally on the instance, but it's unclear if that is the intended solution. I noticed an old comment suggesting an external override is expected, but shouldn't it be configurable via constructor arguments?
To Reproduce
Expected behavior
python-gnupgshould gracefully handleutf-8encoded non-Latin-1 inputs and passphrases without failing onlatin-1encoding limitations.Screenshots
N/A
Environment
Additional information
gpg.encoding = 'utf-8'immediately after GPG instantiation seems to resolve the exception