Flask logging error: "TypeError findCaller() takes from 1 to 2 position arguments but 3 were given" on app.run (Python 3.8)

Viewed 1983

I've got a Flask application working like a charm in Python 3.7 but when I try to run it in Python 3.8, I get the following:

Traceback (most recent call last):
  File "index.py", line 1410, in <module>
    app.run(host='0.0.0.0', port='9000', extra_files=['config'])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py", line 990, in run
    run_simple(host, port, self, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/werkzeug/serving.py", line 1039, in run_simple
    log_startup(s)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/werkzeug/serving.py", line 982, in log_startup
    _log(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/werkzeug/_internal.py", line 113, in _log
    getattr(_logger, type)(message.rstrip(), *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/logging/__init__.py", line 1434, in info
    self._log(INFO, msg, args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/logging/__init__.py", line 1565, in _log
    fn, lno, func, sinfo = self.findCaller(stack_info, stacklevel)
TypeError: findCaller() takes from 1 to 2 positional arguments but 3 were given

As I understand it, Flask and Werkzeug both support Python 3.8 and and so I'm confused as to why it seems as though Flask and Werkzeug seem to be causing this issue (they're both to up to date as well). Further, reading through the docs, the app.run method hasn't changed in recent versions (in a way that might explain this error).

Has anyone else encountered this issue?

1 Answers

A new argument called stacklevel was added in finCaller() function in Python 3.8. If you or the packages you use has rewritten the findCaller() with only two arguments. It will throw the error TypeError: findCaller() takes from 1 to 2 positional arguments but 3 were given.

To fix this, you will need to add the new argument to the findCaller function you have rewritten:

def findCaller(self, stack_info=False, stacklevel=1):

If the findCaller function that being rewritten is in other packages, you can submit an RP to fix it, just like these:

Related