Attempted to read or stream content, but the content has already been streamed. This can happen if you use a method like `.iter_lines()` and then attempt to read th entire response body afterwards, e.g. ```py response = await client.post(...) async for line in response
| 606 | |
| 607 | |
| 608 | class StreamAlreadyConsumed(AnthropicError): |
| 609 | """ |
| 610 | Attempted to read or stream content, but the content has already |
| 611 | been streamed. |
| 612 | |
| 613 | This can happen if you use a method like `.iter_lines()` and then attempt |
| 614 | to read th entire response body afterwards, e.g. |
| 615 | |
| 616 | ```py |
| 617 | response = await client.post(...) |
| 618 | async for line in response.iter_lines(): |
| 619 | ... # do something with `line` |
| 620 | |
| 621 | content = await response.read() |
| 622 | # ^ error |
| 623 | ``` |
| 624 | |
| 625 | If you want this behaviour you'll need to either manually accumulate the response |
| 626 | content or call `await response.read()` before iterating over the stream. |
| 627 | """ |
| 628 | |
| 629 | def __init__(self) -> None: |
| 630 | message = ( |
| 631 | "Attempted to read or stream some content, but the content has " |
| 632 | "already been streamed. " |
| 633 | "This could be due to attempting to stream the response " |
| 634 | "content more than once." |
| 635 | "\n\n" |
| 636 | "You can fix this by manually accumulating the response content while streaming " |
| 637 | "or by calling `.read()` before starting to stream." |
| 638 | ) |
| 639 | super().__init__(message) |
| 640 | |
| 641 | |
| 642 | class ResponseContextManager(Generic[_APIResponseT]): |