binary-husky/gpt_academic · error · RuntimeError

NEWBING_COOKIES未填写或有格式错误。

Error message

NEWBING_COOKIES未填写或有格式错误。

What it means

Raised in the NewBing loader thread when NEWBING_COOKIES is a non-empty string longer than 100 chars (so it looks like JSON cookies were supplied) but json.loads(NEWBING_COOKIES) throws. The thread marks itself failed, sends '[Local Message] NEWBING_COOKIES未填写或有格式错误。' to the parent, then raises RuntimeError with the same text.

Source

Thrown at request_llms/bridge_newbingfree.py:149

        self.local_history = []
        if (self.newbing_model is None) or (not self.success):
            # 代理设置
            proxies, NEWBING_COOKIES = get_conf("proxies", "NEWBING_COOKIES")
            if proxies is None:
                self.proxies_https = None
            else:
                self.proxies_https = proxies["https"]

            if (NEWBING_COOKIES is not None) and len(NEWBING_COOKIES) > 100:
                try:
                    cookies = json.loads(NEWBING_COOKIES)
                except:
                    self.success = False
                    tb_str = "\n```\n" + trimmed_format_exc() + "\n```\n"
                    self.child.send(f"[Local Message] NEWBING_COOKIES未填写或有格式错误。")
                    self.child.send("[Fail]")
                    self.child.send("[Finish]")
                    raise RuntimeError(f"NEWBING_COOKIES未填写或有格式错误。")
            else:
                cookies = None

            try:
                self.newbing_model = NewbingChatbot(
                    proxy=self.proxies_https, cookies=cookies
                )
            except:
                self.success = False
                tb_str = "\n```\n" + trimmed_format_exc() + "\n```\n"
                self.child.send(
                    f"[Local Message] 不能加载Newbing组件,请注意Newbing组件已不再维护。{tb_str}"
                )
                self.child.send("[Fail]")
                self.child.send("[Finish]")
                raise RuntimeError(f"不能加载Newbing组件,请注意Newbing组件已不再维护。")

        self.success = True

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Replace NEWBING_COOKIES with a valid JSON array of {name, value} objects exported by a cookie-export extension, or leave it None/empty to run cookie-less.
  2. Validate with python -c "import json;json.load(open('config.py'))" style check: json.loads(NEWBING_COOKIES) must not raise.
  3. Ensure no smart quotes/trailing commas/single quotes; use double quotes throughout.
  4. Re-run the loader after fixing; the failed handle resets and retries.

Example fix

// before (config)
NEWBING_COOKIES = "[{name: 'MUID', value: 'ABC'}]"   # single quotes -> json.loads fails

# after
NEWBING_COOKIES = '[{"name": "MUID", "value": "ABC"}]'  # valid JSON, double quotes
Defensive patterns

Strategy: validation

Validate before calling

import json
def newbing_cookies_valid(NEWBING_COOKIES) -> bool:
    if NEWBING_COOKIES is None or len(NEWBING_COOKIES) <= 100:
        return True  # treated as no cookies
    try:
        json.loads(NEWBING_COOKIES)
        return True
    except json.JSONDecodeError:
        return False
assert newbing_cookies_valid(NEWBING_COOKIES), 'fix NEWBING_COOKIES JSON'

Type guard

null

Try / catch

try:
    handle = NewBingHandle()
except RuntimeError as e:
    if 'NEWBING_COOKIES' in str(e):
        guide_user_to_fix_cookie_json()

Prevention

When it happens

Trigger: Configuring NEWBING_COOKIES in shared_utils/config with invalid JSON — trailing commas, single quotes, smart quotes pasted from a browser, a raw cookie-header string ('K=v; K2=v2') instead of a JSON object, or BOM/whitespace issues.

Common situations: Copying cookies from browser devtools in the wrong format (header string vs JSON array from an export extension), hand-editing the config and breaking syntax, or pasting with unescaped newlines.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/f110a319e98eaa96. Report an issue: GitHub.