woonizzooni

locust 실행시 jinja2.ext.do의 KeyError: 'extensions' 에러 본문

Programming/Python

locust 실행시 jinja2.ext.do의 KeyError: 'extensions' 에러

woonizzooni 2021. 5. 12. 14:05

 

아래와 같은 에러 발생시

      app.jinja_options["extensions"].append("jinja2.ext.do")

      KeyError: 'extensions'

$ .venv/bin/locust -f service.py --host="http://localhost:8080" -P 8088

Traceback (most recent call last):
  File "/Users/.../tools/kk/.venv/bin/locust", line 8, in
      sys.exit(main())
  File "/Users/.../tools/kk/.venv/lib/python3.9/site-packages/locust/main.py", line 286, in main
      web_ui = environment.create_web_ui(
  File "/Users/.../tools/kk/.venv/lib/python3.9/site-packages/locust/env.py", line 170, in create_web_ui
      self.web_ui = WebUI(

  File "/Users/.../tools/kk/.venv/lib/python3.9/site-packages/locust/web.py", line 102, in __init__
      app.jinja_options["extensions"].append("jinja2.ext.do")

KeyError: 'extensions'

 

 

문제의 파일 web.py을 열고 102라인을 아래와 같이 변경 : app.jinja_env.add_extension('jinja2.ext.do')

 68     def __init__(
 69         self,
 70         environment,
 71         host,
 72         port,
 73         auth_credentials=None,
 74         tls_cert=None,
 75         tls_key=None,
 76         stats_csv_writer=None,
 77         delayed_start=False,
 78     ):
 79         """
 80         Create WebUI instance and start running the web server in a separate greenlet (self.greenlet)
 81
 82         Arguments:
 83         environment: Reference to the current Locust Environment
 84         host: Host/interface that the web server should accept connections to
 85         port: Port that the web server should listen to
 86         auth_credentials:  If provided, it will enable basic auth with all the routes protected by default.
 87                            Should be supplied in the format: "user:pass".
 88         tls_cert: A path to a TLS certificate
 89         tls_key: A path to a TLS private key
 90         delayed_start: Whether or not to delay starting web UI until `start()` is called. Delaying web UI start
 91                        allows for adding Flask routes or Blueprints before accepting requests, avoiding errors.
 92         """
 
100         app = Flask(__name__)
101         self.app = app
102         app.jinja_options["extensions"].append("jinja2.ext.do")
        --> app.jinja_env.add_extension('jinja2.ext.do')

 

[참고]

stackoverflow.com/questions/52683386/how-to-use-a-jinja2-extension-direct-from-a-flask-render-template

Comments