Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

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

like image 421
omid jahadi Avatar asked Mar 03 '21 05:03

omid jahadi


People also ask

When () takes 2 positional arguments but 3 were given?

The Python "TypeError: takes 2 positional arguments but 3 were given" occurs for multiple reasons: Forgetting to specify the self argument in a class method. Forgetting to specify a third argument in a function's definition. Passing three arguments to a function that only takes two.

How do you fix takes 1 positional argument but 2 were given?

In this situation, we either have to update the function's declaration and take a second argument or remove the second argument from the function call.

What is a positional argument in Python?

A positional argument in Python is an argument whose position matters in a function call. You have likely used positional arguments without noticing. For instance: def info(name, age): print(f"Hi, my name is {name}.

What is positional argument follows keyword argument?

The Python SyntaxError: positional argument follows keyword argument occurs when you try to specify a positional argument after a keyword argument in a function call.


1 Answers

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
like image 196
Lohith Avatar answered Oct 23 '22 17:10

Lohith