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

Fix BytesWarning when logging response status/content #131

Merged
merged 1 commit into from
Jul 15, 2023

Conversation

wdoekes
Copy link
Contributor

@wdoekes wdoekes commented Jan 17, 2023

Fixes the following, seen with Python 3.10.6:

  logger.debug(f"Status code: {resp.status_code}, output: {resp.content}")
proxmoxer/core.py:145: BytesWarning: str() on a bytes instance

Fixes the following, seen with Python 3.10.6:

      logger.debug(f"Status code: {resp.status_code}, output: {resp.content}")
    proxmoxer/core.py:145: BytesWarning: str() on a bytes instance
wdoekes referenced this pull request Jan 17, 2023
@jhollowe jhollowe self-assigned this Apr 1, 2023
@jhollowe jhollowe added the type:bug 🐞 The software does not function as intended label Apr 1, 2023
@jhollowe
Copy link
Contributor

jhollowe commented Apr 1, 2023

What API call did you do to have this show up? Do you have a code snippet to reproduce the error this is fixing?

@wdoekes
Copy link
Contributor Author

wdoekes commented Apr 4, 2023

Apparently you need -b on the python command line to unhide the warning:

$ python3 -c 'b=b"";print(f"{b}")'
b''

vs.

$ python3 -b -c 'b=b"";print(f"{b}")'
<string>:1: BytesWarning: str() on a bytes instance
b''

or

$ PYTHONWARNINGS='default,default::BytesWarning,error::BytesWarning' python3 -b -c 'b=b"";print(f"{b}")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
BytesWarning: str() on a bytes instance

or

$ python3 -bb -c 'b=b"";print(f"{b}")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
BytesWarning: str() on a bytes instance

Without at least one -b you won't get the BytesWarnings. Not sure what the rationale is there.

@wdoekes
Copy link
Contributor Author

wdoekes commented Apr 4, 2023

So, I did some googling and came across this thread https://mail.python.org/archives/list/python-dev@python.org/thread/XBIZSPXCSH4KHPX7A6W7XB3H26LLNZQ4/ -- it discusses the removal of the -b functionality.

Not sure why that deprecation would be forced upon us, as the -b feature seems super useful to me:

$ python3 -b -c 'b=b"\xe2\x82\xac";c=b.decode();print(b=="€",c=="€")'
<string>:1: BytesWarning: Comparison between bytes and string
False True

@jhollowe jhollowe merged commit d45c72d into proxmoxer:develop Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug 🐞 The software does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants