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
Allow returning raw bytes from a request, without attempting to decode. #136
Conversation
Example usage to fetch a user's profile image to a file:
|
Oh! That's actually pretty cool. |
Codecov Report
@@ Coverage Diff @@
## dev #136 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 947 953 +6
=========================================
+ Hits 947 953 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
… `poetry run mypy homeassistant_api --show-error-codes`
For some reason, mypy didn't like the typechecking in the ternary operator, but is fine with the statement.
TIL how to use There was a type error detected by mypy unrelated to my changes ( |
Mypy can be weird like that sometimes lol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Sorry, one last tweak - copied the wrong line earlier, thank you type-checking. |
Some API calls can return binary data, e.g. fetching a user's profile image (e.g. api path like
/api/image/serve/<hash>/512x512
).Currently this library attempts to decode all responses from
bytes
tostr
using the defaultutf-8
encoding, which fails for API calls returning binary data since the first byte of e.g. JPEG data (0xFF
) can't be decoded to text.This PR adds a by-default-no-change-to-external-behaviour flag to the
RawClient.request
method to optionally disable decoding for that request, just returning the raw bytes.