What is the reason to not return body of ClientResponse after connecction is closed? #7905
-
Hi. I am trying to understand why I can't read body via public read() method after connection is closed.
As far as I can see I can get text() and json() data after conenction is closed. But I cannot get bytes using public method read(). I can do it using private _body as in the code below.
I have looked into read() method. And it should return body if it's present. But only inside the context of response. Which is odd, as object already has body. P.S. Context why I do it whis way. I try to create simplistic api client. I can create my response adapter which will get needed data from ClientResponse but it seems to be an overhead when ClientResponse has all needed info and methods.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I would suggest you create that adapter. Even if we changed this, I would still recommend not passing around a Response object outside of its context. It is not designed like that, and we'll probably break your code in some way later on. Also, creating a whole new ClientSession() in every request isn't very efficient and not doing you any favours. If you don't care about performance, then you can just use https://docs.aiohttp.org/en/stable/client_reference.html#basic-api and drop half that code. |
Beta Was this translation helpful? Give feedback.
-
Correct. You could add |
Beta Was this translation helpful? Give feedback.
I would suggest you create that adapter. Even if we changed this, I would still recommend not passing around a Response object outside of its context. It is not designed like that, and we'll probably break your code in some way later on.
Also, creating a whole new ClientSession() in every request isn't very efficient and not doing you any favours. If you don't care about performance, then you can just use https://docs.aiohttp.org/en/stable/client_refere…