MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / StreamAlreadyConsumed

Class StreamAlreadyConsumed

src/opencode_ai/_response.py:565–596  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

563
564
565class StreamAlreadyConsumed(OpencodeError):
566 """
567 Attempted to read or stream content, but the content has already
568 been streamed.
569
570 This can happen if you use a method like `.iter_lines()` and then attempt
571 to read th entire response body afterwards, e.g.
572
573 ```py
574 response = await client.post(...)
575 async for line in response.iter_lines():
576 ... # do something with `line`
577
578 content = await response.read()
579 # ^ error
580 ```
581
582 If you want this behaviour you'll need to either manually accumulate the response
583 content or call `await response.read()` before iterating over the stream.
584 """
585
586 def __init__(self) -> None:
587 message = (
588 "Attempted to read or stream some content, but the content has "
589 "already been streamed. "
590 "This could be due to attempting to stream the response "
591 "content more than once."
592 "\n\n"
593 "You can fix this by manually accumulating the response content while streaming "
594 "or by calling `.read()` before starting to stream."
595 )
596 super().__init__(message)
597
598
599class ResponseContextManager(Generic[_APIResponseT]):

Callers 2

readMethod · 0.85
readMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected