sqlmapproject/sqlmap · error · SqlmapGenericException
missing function 'preprocess(req)' in preprocess script
Error message
missing function 'preprocess(req)' in preprocess script '%s'
What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/core/option.py:1032 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sqlmapproject/sqlmap@0a35b20e39 (2026-08-26).
Data as JSON: /api/errors/ad5878e71a21fc7c.
Report an issue: GitHub.
Appendix: source
Thrown at lib/core/option.py:1032
except Exception as ex:
raise SqlmapSyntaxException("cannot import preprocess module '%s' (%s)" % (getUnicode(filename[:-3]), getSafeExString(ex)))
for name, function in inspect.getmembers(module, inspect.isfunction):
try:
if name == "preprocess" and inspect.getargspec(function).args and all(_ in inspect.getargspec(function).args for _ in ("req",)):
found = True
kb.preprocessFunctions.append(function)
function.__name__ = module.__name__
break
except ValueError: # Note: https://github.com/sqlmapproject/sqlmap/issues/4357
pass
if not found:
errMsg = "missing function 'preprocess(req)' "
errMsg += "in preprocess script '%s'" % script
raise SqlmapGenericException(errMsg)
else:
try:
function(_urllib.request.Request("http://localhost"))
except Exception as ex:
tbMsg = traceback.format_exc()
if conf.debug:
dataToStdout(tbMsg)
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.PREPROCESS, suffix=".py")
os.close(handle)
openFile(filename, "w+").write("#!/usr/bin/env\n\ndef preprocess(req):\n pass\n")
openFile(os.path.join(os.path.dirname(filename), "__init__.py"), "w+").write("pass")
errMsg = "function 'preprocess(req)' "
errMsg += "in preprocess script '%s' " % script
errMsg += "had issues in a test run ('%s'). " % getSafeExString(ex)View on GitHub (pinned to 0a35b20e39)