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
| 582 | |
| 583 | |
| 584 | class StreamAlreadyConsumed(OpenAIError): |
| 585 | """ |
| 586 | Attempted to read or stream content, but the content has already |
| 587 | been streamed. |
| 588 | |
| 589 | This can happen if you use a method like `.iter_lines()` and then attempt |
| 590 | to read th entire response body afterwards, e.g. |
| 591 | |
| 592 | ```py |
| 593 | response = await client.post(...) |
| 594 | async for line in response.iter_lines(): |
| 595 | ... # do something with `line` |
| 596 | |
| 597 | content = await response.read() |
| 598 | # ^ error |
| 599 | ``` |
| 600 | |
| 601 | If you want this behaviour you'll need to either manually accumulate the response |
| 602 | content or call `await response.read()` before iterating over the stream. |
| 603 | """ |
| 604 | |
| 605 | def __init__(self) -> None: |
| 606 | message = ( |
| 607 | "Attempted to read or stream some content, but the content has " |
| 608 | "already been streamed. " |
| 609 | "This could be due to attempting to stream the response " |
| 610 | "content more than once." |
| 611 | "\n\n" |
| 612 | "You can fix this by manually accumulating the response content while streaming " |
| 613 | "or by calling `.read()` before starting to stream." |
| 614 | ) |
| 615 | super().__init__(message) |
| 616 | |
| 617 | |
| 618 | class ResponseContextManager(Generic[_APIResponseT]): |