6

I have a scraping project with django. Everything work fine, but terminal shows this error:

builtins.TypeError: _findCaller() takes from 1 to 2 positional arguments but 3 were given

What is this error?

How can I handle it?

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

omid jahadi
  • 151
  • 1
  • 12
  • Just by looking at error it is difficult to say what is causing issue, it might have raised while porting py2 to py3 or by passing multiple parameters to a function or with print or logging statements, everything is just a random guess. – Lohith Mar 03 '21 at 07:05
  • @Lohith Thank you ... What do you need to recognize what's the cause of error? – omid jahadi Mar 03 '21 at 07:15
  • can't make a random guess, it would have been good if there was any stack trace which caused that error to happen. – Lohith Mar 03 '21 at 07:20
  • @Lohith updated – omid jahadi Mar 03 '21 at 07:52
  • From trace it is clear that you should be passing only one positional argument, and `_findCaller` seems to be class object instance so self(object) reference will be default argument in that case. – Anvesh Mar 03 '21 at 07:56
  • Does this answer your question? [TypeError: method() takes 1 positional argument but 2 were given](https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given) – Anvesh Mar 03 '21 at 07:59

2 Answers2

5

This could be result of compatibility with older versions as per the documention in ..logging/__init__.py setting _srcfile = None should avoid raising TypeError

_srcfile is only used in conjunction with sys._getframe(). To provide compatibility with older versions of Python, set _srcfile to None if _getframe() is not available; this value will prevent findCaller() from being called. You can also do this if you want to avoid the overhead of fetching caller information, even when _getframe() is available.

  if not hasattr(sys, '_getframe'):
     _srcfile = None
Lohith
  • 866
  • 1
  • 9
  • 25
  • 2
    I changed it from this: `_srcfile = os.path.normcase(addLevelName.__code__.co_filename)` to this: `_srcfile = None` – Michal May 07 '21 at 08:42
  • Instead of modifying the logging module you can do `import logging` `logging._srcfile = None` – Octetz Aug 24 '22 at 03:26
1

Please try this: pip install -U twisted then do pip install -U attrs

Corey Levinson
  • 1,553
  • 17
  • 25