-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Accessing Response.text can fail with an AttributeError #2928
Comments
I see at least a logical error: |
Thank you for the quick response! Then the question is why Also, what should the behavior of According to documentation the |
The life is imperfect. |
Maybe a feasible way would be to avoid the AttributeError thrown by |
Maybe. I need to look into the source deeper. |
@myuz feel free to give it a try |
@webknjaz @asvetlov
Per my understanding What I suggest. 1.raise an error if thoughts, guys? |
@myuz that sounds reasonable to me :-) |
got the same error
|
Long story short
Handling of payloads in the server response is not consistent and can lead to
AttributeError
s since code depends on methods that may not exist. I am willing to try and create a PR that fixes this issue but I'm unsure of what the intended behavior should be.Expected behaviour
We handle payload setting consistently and don't fail when
text
is called after setting a string payload using thebody
property setter.Actual behaviour
The setter for
Response.body
has support for automatic type detection via thePayloadRegistry
. This means that in the above example, the body will be encoded as aStringPayload
. When trying to access this via thetext
property we fail becauseStringPayload
does not have adecode
method.When you set
text
directly any string is decoded tobytes
and set to_body
directly without passing through thePayloadRegistry
.Steps to reproduce
Your environment
Reproduced on aiohttp 2.3.10 and 3.1.2
The text was updated successfully, but these errors were encountered: