{"record":{"id":"ed0968e65e56e8b0","repo":"psf/requests","slug":"unsupported-event-specified-with-event-name-eve","errorCode":null,"errorMessage":"Unsupported event specified, with event name \"{event}\"","messagePattern":"Unsupported event specified, with event name \"(.+?)\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"src/requests/models.py","lineNumber":263,"sourceCode":"            rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)\n            rf.make_multipart(content_type=ft)\n            new_fields.append(rf)\n\n        body, content_type = encode_multipart_formdata(new_fields)\n\n        return body, content_type\n\n\nclass RequestHooksMixin:\n    hooks: dict[str, list[_t.HookType]]\n\n    def register_hook(\n        self, event: str, hook: Iterable[_t.HookType] | _t.HookType\n    ) -> None:\n        \"\"\"Properly register a hook.\"\"\"\n\n        if event not in self.hooks:\n            raise ValueError(f'Unsupported event specified, with event name \"{event}\"')\n\n        if isinstance(hook, Callable):\n            self.hooks[event].append(hook)\n        elif hasattr(hook, \"__iter__\"):\n            self.hooks[event].extend(\n                h for h in hook if isinstance(h, Callable)\n            )  # defensive runtime filter\n\n    def deregister_hook(self, event: str, hook: _t.HookType) -> bool:\n        \"\"\"Deregister a previously registered hook.\n        Returns True if the hook existed, False if not.\n        \"\"\"\n\n        try:\n            self.hooks[event].remove(hook)\n            return True\n        except ValueError:\n            return False","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/models.py#L245-L281","documentation":"Raised by RequestHooksMixin.register_hook when the event name is not already a key in the hooks dict. requests pre-populates hooks with a fixed set of event names (e.g. 'response'); registering a hook against any other event name is rejected because the dispatcher will never fire it. This prevents silently-ignored hooks caused by typos or speculative event names.","triggerScenarios":"Calling request.register_hook('responce', fn) with a typo; inventing an event name like 'request' or 'error' that requests does not emit; passing an event from a config file that does not match the canonical hook names.","commonSituations":"Copy-pasting hook code from a tutorial that uses an outdated or invented event name; building a generic hooks framework on top of requests and assuming arbitrary events are supported.","solutions":["Use one of the canonical events supported by requests — currently 'response' is the primary hook event. Check Session.hooks / Request.hooks keys for the exact set in your version.","Inspect the existing hooks dict (print(request.hooks)) before registering to see accepted event names.","If you need custom event dispatch, layer your own pub/sub on top rather than reusing requests' hooks dict."],"exampleFix":"// before\nrequest.register_hook('error', my_handler)\n\n// after\nrequest.register_hook('response', my_handler)","handlingStrategy":"validation","validationCode":"from requests import Request\n\nSUPPORTED_HOOK_EVENTS = {'response'}\n\ndef safe_register(req: Request, event: str, hook):\n    if event not in SUPPORTED_HOOK_EVENTS:\n        raise ValueError(f'unsupported hook event: {event!r}; supported: {SUPPORTED_HOOK_EVENTS}')\n    req.register_hook(event, hook)","typeGuard":"SUPPORTED_HOOK_EVENTS = {'response'}\n\ndef is_supported_hook_event(event: str) -> bool:\n    return event in SUPPORTED_HOOK_EVENTS","tryCatchPattern":"try:\n    request.register_hook(event, hook)\nexcept ValueError:\n    # unknown event; ignore or log\n    pass","preventionTips":["Use only the canonical events (currently 'response').","Inspect request.hooks keys before registering.","Build your own pub/sub for custom events rather than reusing requests' hooks dict."],"tags":["hooks","valueerror","events","validation","config"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}