{"record":{"id":"f110a319e98eaa96","repo":"binary-husky/gpt_academic","slug":"newbing-cookies","errorCode":null,"errorMessage":"NEWBING_COOKIES未填写或有格式错误。","messagePattern":"NEWBING_COOKIES未填写或有格式错误。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_newbingfree.py","lineNumber":149,"sourceCode":"        self.local_history = []\n        if (self.newbing_model is None) or (not self.success):\n            # 代理设置\n            proxies, NEWBING_COOKIES = get_conf(\"proxies\", \"NEWBING_COOKIES\")\n            if proxies is None:\n                self.proxies_https = None\n            else:\n                self.proxies_https = proxies[\"https\"]\n\n            if (NEWBING_COOKIES is not None) and len(NEWBING_COOKIES) > 100:\n                try:\n                    cookies = json.loads(NEWBING_COOKIES)\n                except:\n                    self.success = False\n                    tb_str = \"\\n```\\n\" + trimmed_format_exc() + \"\\n```\\n\"\n                    self.child.send(f\"[Local Message] NEWBING_COOKIES未填写或有格式错误。\")\n                    self.child.send(\"[Fail]\")\n                    self.child.send(\"[Finish]\")\n                    raise RuntimeError(f\"NEWBING_COOKIES未填写或有格式错误。\")\n            else:\n                cookies = None\n\n            try:\n                self.newbing_model = NewbingChatbot(\n                    proxy=self.proxies_https, cookies=cookies\n                )\n            except:\n                self.success = False\n                tb_str = \"\\n```\\n\" + trimmed_format_exc() + \"\\n```\\n\"\n                self.child.send(\n                    f\"[Local Message] 不能加载Newbing组件，请注意Newbing组件已不再维护。{tb_str}\"\n                )\n                self.child.send(\"[Fail]\")\n                self.child.send(\"[Finish]\")\n                raise RuntimeError(f\"不能加载Newbing组件，请注意Newbing组件已不再维护。\")\n\n        self.success = True","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_newbingfree.py#L131-L167","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Validate with python -c \"import json;json.load(open('config.py'))\" style check: json.loads(NEWBING_COOKIES) must not raise.","Ensure no smart quotes/trailing commas/single quotes; use double quotes throughout.","Re-run the loader after fixing; the failed handle resets and retries."],"exampleFix":"// before (config)\nNEWBING_COOKIES = \"[{name: 'MUID', value: 'ABC'}]\"   # single quotes -> json.loads fails\n\n# after\nNEWBING_COOKIES = '[{\"name\": \"MUID\", \"value\": \"ABC\"}]'  # valid JSON, double quotes","handlingStrategy":"validation","validationCode":"import json\ndef newbing_cookies_valid(NEWBING_COOKIES) -> bool:\n    if NEWBING_COOKIES is None or len(NEWBING_COOKIES) <= 100:\n        return True  # treated as no cookies\n    try:\n        json.loads(NEWBING_COOKIES)\n        return True\n    except json.JSONDecodeError:\n        return False\nassert newbing_cookies_valid(NEWBING_COOKIES), 'fix NEWBING_COOKIES JSON'","typeGuard":"null","tryCatchPattern":"try:\n    handle = NewBingHandle()\nexcept RuntimeError as e:\n    if 'NEWBING_COOKIES' in str(e):\n        guide_user_to_fix_cookie_json()","preventionTips":["Export cookies as a JSON [{name,value}] array, not a header string","json.loads-validate the config string at startup","Leave NEWBING_COOKIES None when not using cookies"],"tags":["newbing","cookies","config","json","validation"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}