PyCQA / PyCQA/bandit

Runtime error with output report

Open
#514 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.3k
Forks
835
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Running into this error when executing:


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_DIR="`realpath $DIR/../mypackage`"
EXCLUDES=$REPO_DIR/version.py
bandit "$REPO_DIR" -ll -r -x "$EXCLUDES"```

Output is

[main]  INFO    profile include tests: None
[main]  INFO    profile exclude tests: None
[main]  INFO    cli include tests: None
[main]  INFO    cli exclude tests: None
[main]  INFO    running on Python 3.7.3
Traceback (most recent call last):
  File "c:\users\pimentelc\appdata\local\continuum\anaconda3\envs\venv-datasci\lib\site-packages\bandit\core\manager.py", line 169, in output_results
    conf_level=conf_level, lines=lines)
  File "c:\users\pimentelc\appdata\local\continuum\anaconda3\envs\venv-datasci\lib\site-packages\bandit\formatters\text.py", line 167, in report
    with fileobj:
AttributeError: __enter__

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\pimentelc\appdata\local\continuum\anaconda3\envs\venv-datasci\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\pimentelc\appdata\local\continuum\anaconda3\envs\venv-datasci\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\pimentelc\AppData\Local\Continuum\anaconda3\envs\venv-datasci\Scripts\bandit.exe\__main__.py", line 9, in <module>
  File "c:\users\pimentelc\appdata\local\continuum\anaconda3\envs\venv-datasci\lib\site-packages\bandit\cli\main.py", line 403, in main
    args.msg_template)
  File "c:\users\pimentelc\appdata\local\continuum\anaconda3\envs\venv-datasci\lib\site-packages\bandit\core\manager.py", line 173, in output_results
    "%s" % (output_format, str(e)))
RuntimeError: Unable to output report using 'txt' formatter: __enter__

Bandit version
bandit 1.6.0, Anaconda python 3.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the command with Bandit 1.6.0 and Python 3.7, then start in bandit/core/manager.py around output_results and bandit/formatters/text.py around report. Confirm the failure path for the txt formatter and ensure the report completes without the enter error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.