GurpreetKang / BitwardenDecrypt

Decrypts an encrypted Bitwarden data.json file.
GNU General Public License v3.0
245 stars 30 forks source link

Without --output option, prints a Python bytes literal instead of the raw data #24

Open x11x opened 12 months ago

x11x commented 12 months ago

When using without the --output option, it prints a Python bytes literal string containing the JSON to stdout like (truncated):

b'{\n  "folders": [\n    {\n      "id":  ...

I think print(decryptedJSON.encode("utf-8")) needs to be changed to just print(decryptedJSON) (L601). It looks like you were trying to ensure output is UTF-8 encoded. I think the way to do this is calling sys.stdout.reconfigure(encoding='utf-8') before the print call. (See https://stackoverflow.com/questions/4374455/how-to-set-sys-stdout-encoding-in-python-3 for this and other ways to do this). Or, leave it up to the user to set the encoding they want (e.g. they can control this independently of your script by using the PYTHONIOENCODING environment variable, or configuring their system). In practice, this is often an issue for Windows users because the default encoding in the terminal is not always UTF-8, but on other platforms the encoding is usually set to a sane default. So you could special-case Windows and leave the stdout encoding as is on other platforms.