builtins.TypeError: _findCaller() 需要 1 到 2 个位置参数,但 django 中给出了 3 个

omi*_*adi 6 python django

我有一个 django 的抓取项目。一切正常,但终端显示此错误:

builtins.TypeError:_findCaller() 接受 1 到 2 个位置参数,但给出了 3 个

这是什么错误?

我该如何处理?

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 134, in err
    msg(failure=_stuff, why=_why, isError=1, **kw)
  File "/usr/lib/python3/dist-packages/twisted/python/threadable.py", line 53, in sync
    return function(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 286, in msg
    _publishNew(self._publishPublisher, actualEventDict, textFromEventDict)
  File "/usr/lib/python3/dist-packages/twisted/logger/_legacy.py", line 154, in publishToNewObserver
    observer(eventDict)
--- <exception caught here> ---
  File "/usr/lib/python3/dist-packages/twisted/logger/_observer.py", line 131, in __call__
    observer(event)
  File "/usr/lib/python3/dist-packages/twisted/logger/_legacy.py", line 93, in __call__
    self.legacyObserver(event)
  File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 595, in emit
    _publishNew(self._newObserver, eventDict, textFromEventDict)
  File "/usr/lib/python3/dist-packages/twisted/logger/_legacy.py", line 154, in publishToNewObserver
    observer(eventDict)
  File "/usr/lib/python3/dist-packages/twisted/logger/_stdlib.py", line 115, in __call__
    self.logger.log(
  File "/usr/lib/python3.8/logging/__init__.py", line 1500, in log
    self._log(level, msg, args, **kwargs)
  File "/usr/lib/python3.8/logging/__init__.py", line 1565, in _log
    fn, lno, func, sinfo = self.findCaller(stack_info, stacklevel)
builtins.TypeError: _findCaller() takes from 1 to 2 positional arguments but 3 were given

Run Code Online (Sandbox Code Playgroud)

Loh*_*ith 5

这可能是与旧版本兼容的结果,根据..logging/__init__.py 设置中的文档_srcfile = None应避免引发TypeError

_srcfile 仅与 sys._getframe() 结合使用。为了提供与旧版本 Python 的兼容性,如果 _getframe() 不可用,请将 _srcfile 设置 为 None ;该值将阻止 调用 findCaller()。如果您想避免获取调用者信息的开销,即使 _getframe() 可用,您也可以这样做。

  if not hasattr(sys, '_getframe'):
     _srcfile = None
Run Code Online (Sandbox Code Playgroud)

  • 我将其从:`_srcfile = os.path.normcase(addLevelName.__code__.co_filename)`更改为:`_srcfile = None` (2认同)