79495775

Date: 2025-03-09 10:44:34
Score: 0.5
Natty:
Report link

How did you create the virtual environment? Did you activate it once it is created?
Sometimes, we can miss activating the environment and installing the necessary dependencies on it.

I personally use uv for creating and managing virtual environments:

$ uv venv
$ source .venv/bin/activate
$ (venv) pip install python-gnupg==0.5.4

If you don't use uv, you can always follow this tutorial venv — Creation of virtual environments, you'll get the same result.

I've just run that snippet of code and it worked perfectly fine within my virtual environment. Make sure you activate and install the correct gnupg python dependency.

Regarding to the formatter of the result. What you're printing is a byte-formatted string.
In case you want a more human-readable output you can always do the following:

if encrypted_data.ok:
    print("Data encrypted successfully.")
    encrypted_str: str = bytes(encrypted_data.data).decode(encoding="utf-8")
    with open(file=out_file, mode="w") as encrypted_file:
        encrypted_file.write(encrypted_str)
    print(encrypted_str)

I've just casted the encrypted_data.data to bytes() and decoded it in UTF-8.

Reasons:
  • Blacklisted phrase (1): this tutorial
  • Whitelisted phrase (-1): it worked
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How did you
  • Low reputation (1):
Posted by: fqlenos