Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
x11x opened this issue Aug 7, 2023 · 0 comments · May be fixed by #25
Open

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

x11x opened this issue Aug 7, 2023 · 0 comments · May be fixed by #25

Comments

@x11x
Copy link

x11x commented Aug 7, 2023

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.

x11x added a commit to x11x/BitwardenDecrypt that referenced this issue Aug 7, 2023
Properly writes JSON output to the file, instead of writing the `__repr__` of a Python `bytes` literal containing the JSON.

Also changes `decryptBitwardenJSON` to return a dictionary instead of JSON-encoded string, and adds `write_json function to handle JSON-encoded output (using `json.dump` instead of `print` or `TextIO.write`).

Fixes GurpreetKang#24
@x11x x11x linked a pull request Aug 7, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant