[英]Flask logging error: "TypeError findCaller() takes from 1 to 2 position arguments but 3 were given" on app.run (Python 3.8)
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:我有一个 Flask 应用程序在 Python 3.7 中像魅力一样工作,但是当我尝试在 Python 3.8 中运行它时,我得到以下信息:
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).据我了解,Flask 和 Werkzeug 都支持 Python 3.8,所以我很困惑为什么 Flask 和 Werkzeug 似乎导致了这个问题(它们都是最新的)。 Further, reading through the docs, the app.run method hasn't changed in recent versions (in a way that might explain this error).
此外,通过阅读文档, app.run 方法在最近的版本中没有改变(以可能解释这个错误的方式)。
Has anyone else encountered this issue?有没有其他人遇到过这个问题?
A new argument called stacklevel
was added in finCaller()
function in Python 3.8.在 Python 3.8 的
finCaller()
函数中添加了一个名为stacklevel
的新参数。 If you or the packages you use has rewritten the findCaller()
with only two arguments.如果您或您使用的包仅用两个参数重写了
findCaller()
。 It will throw the error TypeError: findCaller() takes from 1 to 2 positional arguments but 3 were given
.它会抛出错误
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:要解决此问题,您需要将新参数添加到您重写的
findCaller
函数中:
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:如果被重写的
findCaller
函数在其他包中,你可以提交一个 RP 来修复它,就像这样:
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:在Python 3.7中,我有一个Flask应用程序,就像魅力一样工作,但是当我尝试在Python 3.8中运行它时,我得到了以下信息:
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).据我了解,Flask和Werkzeug都支持Python 3.8,因此对于为何Flask和Werkzeug似乎引起此问题的原因我感到困惑(它们都是最新的)。 Further, reading through the docs, the app.run method hasn't changed in recent versions (in a way that might explain this error).
此外,通过阅读文档,app.run方法在最新版本中没有更改(以可能解释此错误的方式)。
Has anyone else encountered this issue?还有其他人遇到过这个问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.