diff --git a/bandit/core/config.py b/bandit/core/config.py index 7dbf0a8bb..2dbcbe9fd 100644 --- a/bandit/core/config.py +++ b/bandit/core/config.py @@ -6,6 +6,11 @@ import yaml +try: + import toml +except ImportError: + toml = None + from bandit.core import constants from bandit.core import extension_loader from bandit.core import utils @@ -31,12 +36,13 @@ def __init__(self, config_file=None): try: f = open(config_file) except OSError: - raise utils.ConfigError( - "Could not read config file.", config_file - ) + raise utils.ConfigError("Could not read config file.", config_file) if config_file.endswith(".toml"): - import toml + if toml is None: + raise utils.ConfigError( + "toml parser not available, reinstall with toml extra" + ) try: with f: