sqlmapproject/sqlmap · error · SqlmapSyntaxException

cannot import postprocess module

Error message

cannot import postprocess module '%s' (%s)

What it means

Once the directory is on sys.path, _setPostprocessFunctions imports the module with __import__ (after invalidating import caches on py3.3+). The call is wrapped in try/except; any import-time failure — syntax error, unresolved third-party import, exception in module top-level code — is re-raised as this SqlmapSyntaxException with the module name and the original exception string in the message.

Solutions

  1. Inspect the inner exception text; it identifies the true import failure (syntax error, missing package, runtime error at top level).
  2. Reproduce standalone: `cd <scripts dir> && python -c "import <module>"` and fix what breaks.
  3. Install missing third-party dependencies or guard non-critical imports.
  4. Remove stale __pycache__ entries and fix any Python 2/3 incompatibilities in the script.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at lib/core/option.py:1099 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/95eea55837e17dd5. Report an issue: GitHub.

Appendix: source

Thrown at lib/core/option.py:1099

            dirname, filename = os.path.split(script)
            dirname = os.path.abspath(dirname)

            infoMsg = "loading postprocess module '%s'" % filename[:-3]
            logger.info(infoMsg)

            if not os.path.exists(os.path.join(dirname, "__init__.py")):
                errMsg = "make sure that there is an empty file '__init__.py' "
                errMsg += "inside of postprocess scripts directory '%s'" % dirname
                raise SqlmapGenericException(errMsg)

            if dirname not in sys.path:
                sys.path.insert(0, dirname)

            try:
                getattr(importlib, "invalidate_caches", lambda: None)()  # Note: py3.3+ only; a script just written into an already-scanned dir is invisible to a cached FileFinder (Windows coarse mtime)
                module = __import__(safeFilepathEncode(filename[:-3]))
            except Exception as ex:
                raise SqlmapSyntaxException("cannot import postprocess module '%s' (%s)" % (getUnicode(filename[:-3]), getSafeExString(ex)))

            for name, function in inspect.getmembers(module, inspect.isfunction):
                if name == "postprocess" and inspect.getargspec(function).args and all(_ in inspect.getargspec(function).args for _ in ("page", "headers", "code")):
                    found = True

                    kb.postprocessFunctions.append(function)
                    function.__name__ = module.__name__

                    break

            if not found:
                errMsg = "missing function 'postprocess(page, headers=None, code=None)' "
                errMsg += "in postprocess script '%s'" % script
                raise SqlmapGenericException(errMsg)
            else:
                try:
                    _, _, _ = function("", {}, None)
                except:

View on GitHub (pinned to 0a35b20e39)