sqlmapproject/sqlmap · error · SqlmapGenericException

function 'preprocess(req)' in preprocess script

Error message

function 'preprocess(req)' in preprocess script '%s' had issues in a test run ('%s'). You can find a template script at '%s'

What it means

As a smoke test, sqlmap calls the discovered preprocess function once with a dummy urllib Request against http://localhost. If that call raises, sqlmap writes a minimal template script to a temp file, prints its path, and raises this error telling the user the test run failed — i.e., the function may import fine but crashes on a representative Request object (wrong attribute access, unhandled exception, bad return type).

Solutions

  1. Rerun with --debug so the full traceback of the failing test invocation is printed to stdout.
  2. Fix the preprocess function so it handles a standard urllib request object and returns the (possibly modified) request; guard against attributes that may be missing.
  3. Compare your script against the template whose path sqlmap prints in the message, and simplify until the dummy call succeeds.
  4. Test the function locally by calling it with `_urllib.request.Request("http://localhost")` in a standalone Python shell.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at lib/core/option.py:1052 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/09747837e6185da2. Report an issue: GitHub.

Appendix: source

Thrown at lib/core/option.py:1052

                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)
                    errMsg += "You can find a template script at '%s'" % filename
                    raise SqlmapGenericException(errMsg)

def _setPostprocessFunctions():
    """
    Loads postprocess function(s) from given script(s)
    """

    if conf.postprocess:
        for script in re.split(PARAMETER_SPLITTING_REGEX, conf.postprocess):
            found = False
            function = None

            script = safeFilepathEncode(script.strip())

            try:
                if not script:
                    continue

                if not os.path.exists(script):

View on GitHub (pinned to 0a35b20e39)