xtekky/gpt4free · error · ResponseError

line[6:]

Error message

line[6:]

What it means

Raised as ResponseError while streaming You.com's /api/streamingSearch SSE feed when an 'event: error' line precedes a data line; the raw bytes after 'data: ' (line[6:]) are passed as the error payload. Note the slice yields bytes, so the raised error carries a bytes message rather than a string.

Source

Thrown at g4f/Provider/needs_auth/You.py:142

            }
            if chat_mode == "custom":
                if debug.logging:
                    print(f"You model: {model}")
                data["selectedAiModel"] = model.replace("-", "_")

            async with session.get(
                f"{cls.url}/api/streamingSearch",
                params=data,
                headers=headers,
                cookies=cookies,
            ) as response:
                await raise_for_status(response)
                async for line in response.iter_lines():
                    if line.startswith(b"event: "):
                        event = line[7:].decode()
                    elif line.startswith(b"data: "):
                        if event == "error":
                            raise ResponseError(line[6:])
                        if event in ["youChatUpdate", "youChatToken"]:
                            data = json.loads(line[6:])
                        if event == "youChatToken" and event in data and data[event]:
                            if data[event].startswith(
                                "#### You've hit your free quota for the Model Agent. For more usage of the Model Agent, learn more at:"
                            ):
                                continue
                            yield data[event]
                        elif event == "youChatUpdate" and "t" in data and data["t"]:
                            if chat_mode == "create":
                                match = re.search(r"!\[(.+?)\]\((.+?)\)", data["t"])
                                if match:
                                    if match.group(1) == "fig":
                                        yield ImagePreview(
                                            match.group(2), messages[-1]["content"]
                                        )
                                    else:
                                        yield ImageResponse(

View on GitHub (pinned to 973504e177)

Solutions

  1. Decode the bytes message (e[0] if tuple, or str) to see the actual upstream reason
  2. Refresh you.com cookies (log in again) if the message indicates auth/quota
  3. Retry with backoff for transient errors; switch provider if persistent

Example fix

# before
for chunk in streaming_call: ...
# ResponseError(b'...') from you.com error event

# after
try:
    for chunk in streaming_call: ...
except g4f.errors.ResponseError as e:
    msg = e.args[0]
    if isinstance(msg, bytes):
        msg = msg.decode('utf-8', 'replace')
    logging.error('you.com error: %s', msg)
Defensive patterns

Strategy: try-catch

Try / catch

from g4f.errors import ResponseError
try:
    for chunk in stream: process(chunk)
except ResponseError as e:
    msg = e.args[0]
    msg = msg.decode('utf-8', 'replace') if isinstance(msg, bytes) else str(msg)
    logging.error('you.com: %s', msg)
    if 'quota' in msg.lower():
        rotate_you_cookies()

Prevention

When it happens

Trigger: You.com streaming endpoint reports an error event: invalid/expired cookies, quota exhaustion, or malformed search parameters.

Common situations: Stale you.com cookies, hitting usage limits, g4f's request payload no longer matching You.com's API expectations after an upstream change.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/733773362a547226. Report an issue: GitHub.