aio-libs / aio-libs/aiohttp

Retrieving raw response (status + headers + body) data from ClientResponse?

Đang mở
#3,877 8 bình luận 1 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
20 giờ 10 phút
Pull request đã merge (30 ngày)
221

Mô tả

I was wondering if there is a way to effectively get the entire raw response from a `ClientResponse` class. Take the following code for example:

```python
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
status = response.status
header = response.raw_headers
resp = await response.read()
```

What I am trying to effectively do is get the _complete_ and _raw_ return from the server -- the status, header, and the response in one. I have checked out the docs, and I see there is no mention for raw complete data, only portions; status, header, and body.

Now, I did think of simply reformatting `status` and `header`, and then adding them to the `resp`, but this seems a bit backward as I would be doing something that `aiohttp` certainly does the opposite of in the background -- which is why I am coming here asking for guidance. Something like so would be a lifesaver:

```python
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
resp = await response.read_raw() # or response.raw() or response.all(), any variation really.
```

Thank you in advance, and any guidance would be appreciated!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.