xtekky/gpt4free · error · RuntimeError

Polling images faild. Code: {response.status}

Error message

Polling images faild. Code: {response.status}

What it means

Raised as RuntimeError by Bing image creation when a poll of the async-results URL returns a non-200 status. Each poll iteration expects HTTP 200 (body may still be 'pending'); any other status means the polling request itself failed and the loop aborts with that code.

Source

Thrown at g4f/Provider/needs_auth/bing/create_images.py:127

            if response.status != 302:
                raise RuntimeError(f"Create images failed. Code: {response.status}")

    redirect_url = response.headers["Location"].replace("&nfy=1", "")
    redirect_url = f"{BING_URL}{redirect_url}"
    request_id = redirect_url.split("id=")[-1]
    async with session.get(redirect_url) as response:
        response.raise_for_status()

    polling_url = (
        f"{BING_URL}/images/create/async/results/{request_id}?q={url_encoded_prompt}"
    )
    start_time = time.time()
    while True:
        if time.time() - start_time > timeout:
            raise RuntimeError(f"Timeout error after {timeout} sec")
        async with session.get(polling_url) as response:
            if response.status != 200:
                raise RuntimeError(f"Polling images faild. Code: {response.status}")
            text = await response.text()
            if not text or "GenerativeImagesStatusPage" in text:
                await asyncio.sleep(1)
            else:
                break
    error = None
    try:
        error = json.loads(text).get("errorMessage")
    except Exception:
        pass
    if error == "Pending":
        raise RuntimeError("Prompt is been blocked")
    elif error:
        raise RuntimeError(error)
    return read_images(text)


def read_images(html_content: str) -> List[str]:

View on GitHub (pinned to 973504e177)

Solutions

  1. Retry the whole create_images call for transient 5xx polls
  2. Refresh Bing cookies if the status suggests auth failure (401/403)
  3. Reduce timeout/latency between submission and polling so the request id stays valid

Example fix

# before
images = create_images(session, prompt, cookies)
# RuntimeError: Polling images faild. Code: 500

# after
for attempt in range(3):
    try:
        images = create_images(session, prompt, cookies)
        break
    except RuntimeError as e:
        if 'Polling images faild' not in str(e) or attempt == 2:
            raise
        time.sleep(5)
Defensive patterns

Strategy: retry

Try / catch

for attempt in range(3):
    try:
        images = create_images(session, prompt, cookies)
        break
    except RuntimeError as e:
        if 'Polling images faild' not in str(e) or attempt == 2:
            raise
        time.sleep(5)

Prevention

When it happens

Trigger: The results endpoint returns 4xx/5xx during polling: expired request id, auth cookies dropped mid-flow, or server-side error serving results.

Common situations: Polling continued too long so the request id expired, cookie session invalidated between submission and polling, transient 5xx on Bing's results endpoint.

Related errors


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