{"record":{"id":"ad5878e71a21fc7c","repo":"sqlmapproject/sqlmap","slug":"missing-function-preprocess-req-in-preprocess-s","errorCode":null,"errorMessage":"missing function 'preprocess(req)' in preprocess script '%s'","messagePattern":"missing function 'preprocess\\(req\\)' in preprocess script '(.+?)'","errorType":"exception","errorClass":"SqlmapGenericException","httpStatus":null,"severity":"error","filePath":"lib/core/option.py","lineNumber":1032,"sourceCode":"            except Exception as ex:\n                raise SqlmapSyntaxException(\"cannot import preprocess module '%s' (%s)\" % (getUnicode(filename[:-3]), getSafeExString(ex)))\n\n            for name, function in inspect.getmembers(module, inspect.isfunction):\n                try:\n                    if name == \"preprocess\" and inspect.getargspec(function).args and all(_ in inspect.getargspec(function).args for _ in (\"req\",)):\n                        found = True\n\n                        kb.preprocessFunctions.append(function)\n                        function.__name__ = module.__name__\n\n                        break\n                except ValueError:  # Note: https://github.com/sqlmapproject/sqlmap/issues/4357\n                    pass\n\n            if not found:\n                errMsg = \"missing function 'preprocess(req)' \"\n                errMsg += \"in preprocess script '%s'\" % script\n                raise SqlmapGenericException(errMsg)\n            else:\n                try:\n                    function(_urllib.request.Request(\"http://localhost\"))\n                except Exception as ex:\n                    tbMsg = traceback.format_exc()\n\n                    if conf.debug:\n                        dataToStdout(tbMsg)\n\n                    handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.PREPROCESS, suffix=\".py\")\n                    os.close(handle)\n\n                    openFile(filename, \"w+\").write(\"#!/usr/bin/env\\n\\ndef preprocess(req):\\n    pass\\n\")\n                    openFile(os.path.join(os.path.dirname(filename), \"__init__.py\"), \"w+\").write(\"pass\")\n\n                    errMsg = \"function 'preprocess(req)' \"\n                    errMsg += \"in preprocess script '%s' \" % script\n                    errMsg += \"had issues in a test run ('%s'). \" % getSafeExString(ex)","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/sqlmapproject/sqlmap/blob/0a35b20e3953d341be6c7ac75ccb0b3362540c8d/lib/core/option.py#L1014-L1050","documentation":"After a successful import, sqlmap inspects all functions of the preprocess module looking for one named exactly 'preprocess' whose signature accepts a single 'req' argument (the callable applied to each HTTP request). If no such function is found, found stays False and this SqlmapGenericException is raised — a contract check that the script exports the required hook with the required signature.","triggerScenarios":"Thrown at lib/core/option.py:1032 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Define a top-level function `def preprocess(req):` in the script; keep the name and the `req` parameter exactly as required.","Make sure the function is defined at module top level, not nested or inside a class, so inspect.getmembers(isfunction) can find it.","Avoid renaming the argument; use `def preprocess(req):` rather than an alternate parameter name, since the check matches on 'req'.","Copy the official template script from sqlmap's data/ directory as a starting point."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0a35b20e3953d341be6c7ac75ccb0b3362540c8d","analyzedAt":"2026-08-26T23:02:52.002Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}