{"record":{"id":"f38276f312231770","repo":"binary-husky/gpt_academic","slug":"self-struct-result-message","errorCode":null,"errorMessage":"self.struct[\"result\"][\"message\"]","messagePattern":"self\\.struct\\[\"result\"\\]\\[\"message\"\\]","errorType":"exception","errorClass":"NotAllowedToAccess","httpStatus":null,"severity":"error","filePath":"request_llms/edge_gpt_free.py","lineNumber":349,"sourceCode":"            or \"https://edgeservices.bing.com/edgesvc/turing/conversation/create\",\n        )\n        if response.status_code != 200:\n            response = self.session.get(\n                \"https://edge.churchless.tech/edgesvc/turing/conversation/create\",\n            )\n        if response.status_code != 200:\n            print(f\"Status code: {response.status_code}\")\n            print(response.text)\n            print(response.url)\n            raise Exception(\"Authentication failed\")\n        try:\n            self.struct = response.json()\n        except (json.decoder.JSONDecodeError, NotAllowedToAccess) as exc:\n            raise Exception(\n                \"Authentication failed. You have not been accepted into the beta.\",\n            ) from exc\n        if self.struct[\"result\"][\"value\"] == \"UnauthorizedRequest\":\n            raise NotAllowedToAccess(self.struct[\"result\"][\"message\"])\n\n    @staticmethod\n    async def create(\n        proxy=None,\n        cookies=None,\n    ):\n        self = _Conversation(async_mode=True)\n        self.struct = {\n            \"conversationId\": None,\n            \"clientId\": None,\n            \"conversationSignature\": None,\n            \"result\": {\"value\": \"Success\", \"message\": None},\n        }\n        self.proxy = proxy\n        proxy = (\n            proxy\n            or os.environ.get(\"all_proxy\")\n            or os.environ.get(\"ALL_PROXY\")","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/edge_gpt_free.py#L331-L367","documentation":"Not an error message but the KeyError source expression: when the parsed conversation-create JSON has result.value == 'UnauthorizedRequest', the code raises NotAllowedToAccess(self.struct['result']['message']). If the result object lacks the 'message' key, Python raises KeyError('message') whose repr is shown — the unauthorized response had no message field.","triggerScenarios":"request_llms/edge_gpt_free.py:349: Bing returns JSON with result.value 'UnauthorizedRequest' but without result.message — invalid/expired conversation signature or cookies; or the struct shape from the proxy differs from the expected schema. The KeyError fires only in the no-message case; otherwise NotAllowedToAccess carries Bing's own message.","commonSituations":"Expired _U cookie producing a minimal error payload; churchless fallback proxy returning a trimmed error body; Bing API change altering the result envelope; async create() initializing a synthetic struct where message is None (that path does not raise, but desynced overrides can).","solutions":["Refresh the Bing cookies — most UnauthorizedRequest errors come from stale credentials","Use .get() so a missing message degrades gracefully and the real status value is still logged","Compare the raw JSON from conversation/create (print response.text) with the expected schema to detect proxy/API changes","Retry with a valid BING_PROXY_URL or default endpoint"],"exampleFix":"# before\nif self.struct[\"result\"][\"value\"] == \"UnauthorizedRequest\":\n    raise NotAllowedToAccess(self.struct[\"result\"][\"message\"])\n\n# after\nif self.struct[\"result\"][\"value\"] == \"UnauthorizedRequest\":\n    raise NotAllowedToAccess(self.struct[\"result\"].get(\"message\") or \"UnauthorizedRequest\")","handlingStrategy":"type-guard","validationCode":"result = struct.get('result', {})\nif result.get('value') == 'UnauthorizedRequest':\n    raise NotAllowedToAccess(result.get('message') or 'UnauthorizedRequest (no message)')","typeGuard":"def has_result_message(struct) -> bool:\n    result = struct.get('result') or {}\n    return isinstance(result.get('message'), str)","tryCatchPattern":"try:\n    ...\nexcept KeyError as e:\n    if e.args and e.args[0] == 'message':\n        logger.error('Bing returned UnauthorizedRequest without message; refresh cookies')\n        raise NotAllowedToAccess('UnauthorizedRequest (no message)') from e\n    raise","preventionTips":["Use .get() on all third-party JSON envelopes","Log the raw struct once when the schema surprises you","Refresh cookies on any UnauthorizedRequest-shaped failure"],"tags":["bing","keyerror","authentication","defensive-coding"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}