vsajip/python-gnupg

Exception when passing bytes to encrypt()

inputvalidation opened this issue · 2 comments

Describe the bug
I am passing bytes to encrypt() and on 0.4.9 it raises this exception:

Traceback (most recent call last):
  <x>
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1709, in encrypt
    result = self.encrypt_file(data, recipients, **kwargs)
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1661, in encrypt_file
    self._handle_io(args, file, result, passphrase=passphrase, binary=True)
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1094, in _handle_io
    p = self._open_subprocess(args, passphrase is not None)
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 993, in _open_subprocess
    result = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=si)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/subprocess.py", line 1639, in _execute_child
    self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not ImportResult

Tried upgrading to 0.5.0 and there the exception is slightly different (as well as highlighting a bug in 0.5.0):

Traceback (most recent call last):
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1120, in _handle_io
    p = self._open_subprocess(args, passphrase is not None)
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1007, in _open_subprocess
    result = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=si, env=self.env)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/subprocess.py", line 1639, in _execute_child
    self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not ImportResult

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  <x>
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1751, in encrypt
    result = self.encrypt_file(data, recipients, **kwargs)
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1703, in encrypt_file
    self._handle_io(args, fileobj_or_path, result, passphrase=passphrase, binary=True)
  File "/home/user/git/.env/lib64/python3.8/site-packages/gnupg.py", line 1131, in _handle_io
    writer.join(0.01)
UnboundLocalError: local variable 'writer' referenced before assignment

Environment

  • OS: CentOS 7, using Python 3.8 from Software Collections
  • Version of this library: 0.4.9 and 0.5.0

You haven't given an example of the code, just the tracebacks - so I can't tell if you're calling the library correctly (it doesn't look like you are, from the information you've given so far - it looks as if you're passing an ImportResult to something, which you shouldn't be). Please post a small standalone example that demonstrates the problem, and double check that you've read the documentation and understand it correctly.

I thought I was but it was not the case. Apologies.