sqlmapproject/sqlmap · error · SqlmapSyntaxException
cannot import preprocess module
Error message
cannot import preprocess module '%s' (%s)
What it means
After confirming the preprocess directory is a package, _setPreprocessFunctions inserts the directory into sys.path and imports the module with __import__ wrapped in try/except. Any exception during import (syntax error, missing dependency, top-level code failing, stale bytecode, Python version incompatibility) is caught and re-raised as this SqlmapSyntaxException; the message embeds both the module name and the original import error string.
Solutions
- Read the inner exception text in the message; it names the actual import-time failure (syntax error, ImportError, missing third-party module, etc.).
- Fix the preprocess script: run `python -c "import <module>"` with the script's directory on PYTHONPATH to reproduce the import error standalone.
- Install any third-party packages the script imports, or remove/fix the code that raises at module import time.
- Delete stale __pycache__/bytecode in the scripts directory and retry.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at lib/core/option.py:1015 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/f1fd22d3743e6e64.
Report an issue: GitHub.
Appendix: source
Thrown at lib/core/option.py:1015
dirname, filename = os.path.split(script)
dirname = os.path.abspath(dirname)
infoMsg = "loading preprocess 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 preprocess 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 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:View on GitHub (pinned to 0a35b20e39)