-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Raising RuntimeError when trying to get empty body encoding #4481
Conversation
@@ -268,6 +268,7 @@ Vladimir Rutsky | |||
Vladimir Shulyak | |||
Vladimir Zakharov | |||
Vladyslav Bondar | |||
Vladyslav Bohaichuk |
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.
this should be one line up
docs/client_reference.rst
Outdated
@@ -1305,6 +1305,8 @@ Response object | |||
decode a response. Some encodings detected by cchardet are not known by | |||
Python (e.g. VISCII). | |||
|
|||
:raise RuntimeError: if body hasn't been read for :term:`cchardet` usage |
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.
:raise RuntimeError: if body hasn't been read for :term:`cchardet` usage | |
:raise RuntimeError: if called before the body has been read, for :term:`cchardet` usage |
aiohttp/client_reqrep.py
Outdated
@@ -938,6 +938,8 @@ def get_encoding(self) -> str: | |||
if mimetype.type == 'application' and mimetype.subtype == 'json': | |||
# RFC 7159 states that the default encoding is UTF-8. | |||
encoding = 'utf-8' | |||
elif self._body is None: | |||
raise RuntimeError("Trying to get encoding of not read body") |
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.
raise RuntimeError("Trying to get encoding of not read body") | |
raise RuntimeError('Cannot guess the encoding of a not yet read body') |
tests/test_client_response.py
Outdated
content = response.content = mock.Mock() | ||
content.read.side_effect = side_effect | ||
|
||
with pytest.raises(RuntimeError): |
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.
with pytest.raises(RuntimeError): | |
with pytest.raises( | |
RuntimeError, | |
match='^Cannot guess the encoding of a not yet read body$', | |
): |
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.
Updated PR, thank's for review
Does it always make sense to check exception message?
Codecov Report
@@ Coverage Diff @@
## master #4481 +/- ##
==========================================
+ Coverage 97.51% 97.51% +<.01%
==========================================
Files 43 43
Lines 8865 8867 +2
Branches 1390 1391 +1
==========================================
+ Hits 8645 8647 +2
Misses 96 96
Partials 124 124
Continue to review full report at Codecov.
|
Thanks! |
) (cherry picked from commit 63a0d10) Co-authored-by: Purusah <16886633+Purusah@users.noreply.github.com>
What do these changes do?
Function get_encoding raise RuntimeError when user is trying to read not present body and header doesn't provide info about encoding
Are there changes in behavior for the user?
Make error more verbose
Related issue number
Fixes #4214
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.