Forums

Error running WSGI application RecursionError: maximum recursion depth exceeded while calling a Python object

Hello,

I have been seeing multiple entries in the server.log which I cannot reproduce on my local version and I am not able to track down. I see the entry in the log but the site doesn't seem to have any issues and keeps working fine. Any ideas what could be the root cause for this? This is the output in the server.log :

2024-01-15 10:34:27 Error running WSGI application
2024-01-15 10:34:27 RecursionError: maximum recursion depth exceeded
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
2024-01-15 10:34:27     response = self.get_response(request)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 143, in get_response
2024-01-15 10:34:27     log_response(
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/site-packages/django/utils/log.py", line 241, in log_response
2024-01-15 10:34:27     getattr(logger, level)(
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1458, in warning
2024-01-15 10:34:27     self._log(WARNING, msg, args, **kwargs)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
2024-01-15 10:34:27     self.handle(record)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1599, in handle
2024-01-15 10:34:27     self.callHandlers(record)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1661, in callHandlers
2024-01-15 10:34:27     hdlr.handle(record)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 952, in handle
2024-01-15 10:34:27     self.emit(record)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1086, in emit
2024-01-15 10:34:27     stream.write(msg + self.terminator)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1475, in error
2024-01-15 10:34:27     self._log(ERROR, msg, args, **kwargs)
2024-01-15 10:34:27 
2024-01-15 10:34:27   File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
2024-01-15 10:34:27     self.handle(record)
...
2024-01-15 10:34:31 
2024-01-15 10:34:31   File "/usr/local/lib/python3.9/logging/__init__.py", line 1083, in emit
2024-01-15 10:34:31     msg = self.format(record)
2024-01-15 10:34:31 
2024-01-15 10:34:31   File "/usr/local/lib/python3.9/logging/__init__.py", line 927, in format
2024-01-15 10:34:31     return fmt.format(record)
2024-01-15 10:34:31   
2024-01-15 10:34:31   File "/usr/local/lib/python3.9/logging/__init__.py", line 663, in format
2024-01-15 10:34:31     record.message = record.getMessage()

[edit by admin: formatting]

Are you using Django? If so, are you calling django.setup somewhere? I've seen that cause similar problems in the past -- it winds up setting things up so that the logging system tries to write logging messages to itself, which leads to that kind of infinite recursion.

If you're not, are you using the logging module in any way in your own code?

Hi Giles, yes I am using Django but I am not calling django.setup within the code. Also, I am not using the logging module, just print("message") within the code.

I have got another error in the log, this time a OSError but I guess related to the previous one:

2024-01-20 18:10:14 OSErrorError running WSGI application
2024-01-20 18:10:14 RecursionError: maximum recursion depth exceeded while calling a Python object
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
2024-01-20 18:10:14     response = self.get_response(request)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 143, in get_response
2024-01-20 18:10:14     log_response(
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/site-packages/django/utils/log.py", line 241, in log_response
2024-01-20 18:10:14     getattr(logger, level)(
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1458, in warning
2024-01-20 18:10:14     self._log(WARNING, msg, args, **kwargs)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
2024-01-20 18:10:14     self.handle(record)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1599, in handle
2024-01-20 18:10:14     self.callHandlers(record)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1661, in callHandlers
2024-01-20 18:10:14     hdlr.handle(record)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 952, in handle
2024-01-20 18:10:14     self.emit(record)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1086, in emit
2024-01-20 18:10:14     stream.write(msg + self.terminator)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1475, in error
2024-01-20 18:10:14     self._log(ERROR, msg, args, **kwargs)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
2024-01-20 18:10:14     self.handle(record)
2024-01-20 18:10:14 
2024-01-20 18:10:14   File "/usr/local/lib/python3.9/logging/__init__.py", line 1599, in handle
2024-01-20 18:10:14     self.callHandlers(record)
2024-01-20 18:10:14
...

Can we take a look at your code? We can see if from our admin interface, but we always ask for permission first.

Hi Giles, yes you can check it. Thanks a lot for taking the time

I can see that the last time the error occurred was two days ago on the 20th. Have you changed anything since then? Do you know how to reproduce the error?

I think it was just a coincidence, I have checked it now and there is a new occurance of this error. Unfortunately it seems a bit random to me, I haven't managed to reproduce it.

Do you have any code (or use any module) that may close either stderr or stdout? It is that part of django.setup that causes the problem, but it could be in different code.

I have just checked, I am not using stderr or stdout in my code but it's used in pandas and numpy which I am using within the application.

It doesn't look like it happening during a request which is pretty weird. Do you spawn any threads on startup?

Not that I am aware of.

Do you see any correlation in access log and error log for the recursion error entries in the server log?

I have managed to reproduce the error but still unclear what the cause is. The website is a PWA and every time that I add it to the home screen and installs the service worker (I have only tested it in iOS Safari) it seems to trigger this error. This is the access log at that point when the error happens:

x - - [25/Jan/2024:21:52:33 +0000] "GET /serviceworker.js HTTP/1.1" 200 1032 "" "Mozilla/5.0 (iPhone; CPU iPhone OS 17_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1" "x" response-time=0.003
x - - [25/Jan/2024:21:52:50 +0000] "GET /members/login HTTP/1.1" 200 2912 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0" "x" response-time=0.005
x - - [25/Jan/2024:21:52:52 +0000] "GET /apple-touch-icon-precomposed.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.759
x - - [25/Jan/2024:21:52:54 +0000] "GET /apple-touch-icon.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=3.237
x - - [25/Jan/2024:21:52:56 +0000] "GET /favicon.ico HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=5.499
x - - [25/Jan/2024:21:52:56 +0000] "GET /static/favicon/favicon_4_iOS.png HTTP/1.1" 200 12460 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=5.370
x - - [25/Jan/2024:21:52:56 +0000] "GET /static/favicon/favicon_4.png HTTP/1.1" 200 14175 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=5.357
x - - [25/Jan/2024:21:52:56 +0000] "GET /static/PWA/icons/apple-icon-180.png HTTP/1.1" 200 4254 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=5.374

Duplicated

What's in the error.log?

This is the entries in the error log that seems to correspond to the access log of my previous comment:

2024-01-25 22:52:50,669: OSErrorError running WSGI application
2024-01-25 22:52:50,688: RecursionError: maximum recursion depth exceeded while calling a Python object
2024-01-25 22:52:50,689:   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
2024-01-25 22:52:50,689:     response = self.get_response(request)
2024-01-25 22:52:50,690: 
2024-01-25 22:52:50,690:   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 143, in get_response
2024-01-25 22:52:50,690:     log_response(
2024-01-25 22:52:50,690: 
2024-01-25 22:52:50,690:   File "/usr/local/lib/python3.9/site-packages/django/utils/log.py", line 241, in log_response
2024-01-25 22:52:50,690:     getattr(logger, level)(
2024-01-25 22:52:50,691: 
2024-01-25 22:52:50,691:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1458, in warning
2024-01-25 22:52:50,691:     self._log(WARNING, msg, args, **kwargs)
2024-01-25 22:52:50,691: 
2024-01-25 22:52:50,691:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
2024-01-25 22:52:50,692:     self.handle(record)
2024-01-25 22:52:50,692: 
2024-01-25 22:52:50,692:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1599, in handle
2024-01-25 22:52:50,692:     self.callHandlers(record)
2024-01-25 22:52:50,692: 
2024-01-25 22:52:50,692:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1661, in callHandlers
2024-01-25 22:52:50,693:     hdlr.handle(record)
2024-01-25 22:52:50,693: 
2024-01-25 22:52:50,693:   File "/usr/local/lib/python3.9/logging/__init__.py", line 952, in handle
2024-01-25 22:52:50,693:     self.emit(record)
2024-01-25 22:52:50,693: 
2024-01-25 22:52:50,693:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1086, in emit
2024-01-25 22:52:50,694:     stream.write(msg + self.terminator)
2024-01-25 22:52:50,694: 
2024-01-25 22:52:50,694:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1475, in error
2024-01-25 22:52:50,694:     self._log(ERROR, msg, args, **kwargs)
...
2024-01-25 22:52:56,386: 
2024-01-25 22:52:56,386:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1587, in _log
2024-01-25 22:52:56,386:     record = self.makeRecord(self.name, level, fn, lno, msg, args,
2024-01-25 22:52:56,387: 
2024-01-25 22:52:56,387:   File "/usr/local/lib/python3.9/logging/__init__.py", line 1556, in makeRecord
2024-01-25 22:52:56,388:     rv = _logRecordFactory(name, level, fn, lno, msg, args, exc_info, func,
2024-01-25 22:52:56,388: 
2024-01-25 22:52:56,388:   File "/usr/local/lib/python3.9/logging/__init__.py", line 312, in __init__
2024-01-25 22:52:56,389:     self.levelname = getLevelName(level)
2024-01-25 22:52:56,389: 
2024-01-25 22:52:56,389:   File "/usr/local/lib/python3.9/logging/__init__.py", line 138, in getLevelName
2024-01-25 22:52:56,390:     result = _levelToName.get(level)

Going back to the access log:

x - - [25/Jan/2024:21:52:50 +0000] "GET /members/login HTTP/1.1" 200 2912 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0" "x" response-time=0.005
x - - [25/Jan/2024:21:52:52 +0000] "GET /apple-touch-icon-precomposed.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.759

...my suspicion would be that something in /members/login is triggering the issue, making those later hits fail. It looks like you're getting 200 response codes for static assets, and 500 status codes -- errors -- for things that I'd expect to 404. The static assets would not be touching Django, just the static files system, while the ones that would 404 would hit Django.

What happens if you temporarily remove the call to translation.activate in that view?

Thanks Giles, I have tried your idea but the same error happens again. My suspicion now is that is something related to the apple-touch-icon because it happens as soon as I add the PWA to the homescreen on iOS, in fact as soon as I clic on "share" on Safari. However, I still don't know what the problem is, I have even created the icon for all the possible sizes so no clue where the error comes from.

<link rel="apple-touch-icon" sizes="57x57" href="/static/favicon/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/static/favicon/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/static/favicon/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/static/favicon/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/static/favicon/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/static/favicon/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/static/favicon/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/static/favicon/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon-180x180.png">

Isolating like that the problem, the access log at the time of the error shows:

x - - [30/Jan/2024:23:34:30 +0000] "GET /apple-touch-icon-precomposed.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.691
x - - [30/Jan/2024:23:34:32 +0000] "GET /apple-touch-icon.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=3.003
x - - [30/Jan/2024:23:34:32 +0000] "GET /static/favicon/favicon.ico HTTP/1.1" 200 15086 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=2.984
x - - [30/Jan/2024:23:34:32 +0000] "GET /static/favicon/favicon-32x32.png HTTP/1.1" 200 1539 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=3.011
x - - [30/Jan/2024:23:34:32 +0000] "GET /static/favicon/favicon-16x16.png HTTP/1.1" 200 993 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=2.987
x - - [30/Jan/2024:23:34:33 +0000] "GET /favicon.ico HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=4.354
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-180x180.png HTTP/1.1" 200 4950 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=2.791
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-120x120.png HTTP/1.1" 200 3340 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.174
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-152x152.png HTTP/1.1" 200 4169 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.171
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-144x144.png HTTP/1.1" 200 3971 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.172
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-114x114.png HTTP/1.1" 200 3122 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=1.081
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-76x76.png HTTP/1.1" 200 2114 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=0.002
x - - [30/Jan/2024:23:34:33 +0000] "GET /static/favicon/apple-touch-icon-72x72.png HTTP/1.1" 499 0 "-" "com.apple.WebKit.Networking/8617.1.17.10.9 CFNetwork/1490.0.4 Darwin/23.2.0" "x" response-time=0.002

Can you establish which bit of the code is making the request to /apple-touch-icon-precomposed.png HTTP/1.1? Calls to /static seem to be fine most of the times.

I think that request must be coming from Safari when installing the PWA, it’s not requested within my code. I’ve added that file to the root directory but the error still happens.

SafariWebContent/ConfiguringWebApplications

Adding it to the root directory will not do anything. You need to add it to the directory that will be served by your static files. See https://help.pythonanywhere.com/pages/DebuggingStaticFiles/

The problem is with these 3 specific files which for some reason are not searched within the /static/ path:

"GET /apple-touch-icon-precomposed.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking
"GET /apple-touch-icon.png HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking
"GET /favicon.ico HTTP/1.1" 500 1180 "-" "com.apple.WebKit.Networking/

Normally they will be search within the STATIC_URL as for example these:

"GET /static/favicon/favicon-16x16.png HTTP/1.1" 200 993 "-" "com.apple.WebKit.Networking/
"GET /static/favicon/apple-touch-icon-180x180.png HTTP/1.1" 200 4950 "-" "com.apple.WebKit.Networking

I think it's now solved, I have added those three files to /static and then on the Pythonanywhere Web tab I have added the directory "/" to point to my static path. Now those three files can be found when requested by Safari and the error is gone. Will keep monitoring it.

Thanks a lot for all the ideas that helped me track down this issue.

Glad to hear that!

Unfortunately another "RecursionError: maximum recursion depth exceeded while calling a Python object" has happened but this time completely unrelated to the static files.

In this occasion the server log looks like:

2024-02-02 21:14:24 *** Starting uWSGI 2.0.20 (64bit) on [Fri Feb  2 20:13:54 2024] ***
2024-02-02 21:14:24 compiled with version: 9.4.0 on 22 July 2022 18:35:26
2024-02-02 21:14:24 os: Linux-5.15.0-1044-aws #49~20.04.1-Ubuntu SMP Mon Aug 21 17:09:32 UTC 2023
2024-02-02 21:14:24 nodename: green-liveweb42
2024-02-02 21:14:24 machine: x86_64
2024-02-02 21:14:24 clock source: unix
2024-02-02 21:14:24 pcre jit disabled
2024-02-02 21:14:24 detected number of CPU cores: 4
2024-02-02 21:14:24 current working directory: /home/xxxx
2024-02-02 21:14:24 detected binary path: /usr/local/bin/uwsgi
2024-02-02 21:14:24 *** dumping internal routing table ***
2024-02-02 21:14:24 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2024-02-02 21:14:24 *** end of the internal routing table ***
2024-02-02 21:14:24 chdir() to /home/xxxx/xxxx
2024-02-02 21:14:24 your processes number limit is 256
2024-02-02 21:14:24 your memory page size is 4096 bytes
2024-02-02 21:14:24 detected max file descriptor number: 123456
2024-02-02 21:14:24 building mime-types dictionary from file /etc/mime.types...
2024-02-02 21:14:24 567 entry found
2024-02-02 21:14:24 lock engine: pthread robust mutexes
2024-02-02 21:14:24 thunder lock: disabled (you can enable it with --thunder-lock)
2024-02-02 21:14:24 uwsgi socket 0 bound to UNIX address /var/sockets/xxx.pythonanywhere.com/socket fd 3
2024-02-02 21:14:24 Python version: 3.9.13 (main, Jul 22 2022, 17:05:13)  [GCC 9.4.0]
2024-02-02 21:14:24 *** Python threads support is disabled. You can enable it with --enable-threads ***
2024-02-02 21:14:24 Python main interpreter initialized at 0x560bad0a6d20
2024-02-02 21:14:24 your server socket listen backlog is limited to 100 connections
2024-02-02 21:14:24 your mercy for graceful operations on workers is 60 seconds
2024-02-02 21:14:24 setting request body buffering size to 65536 bytes
2024-02-02 21:14:24 mapped 334256 bytes (326 KB) for 1 cores
2024-02-02 21:14:24 *** Operational MODE: single process ***
2024-02-02 21:14:24 initialized 38 metrics
2024-02-02 21:14:24 WSGI app 0 (mountpoint='') ready in 24 seconds on interpreter 0x560bad0a6d20 pid: 1 (default app)
2024-02-02 21:14:24 *** uWSGI is running in multiple interpreter mode ***
2024-02-02 21:14:24 gracefully (RE)spawned uWSGI master process (pid: 1)
2024-02-02 21:14:24 spawned uWSGI worker 1 (pid: 12, cores: 1)
2024-02-02 21:14:24 metrics collector thread started
2024-02-02 21:14:24 spawned 2 offload threads for uWSGI worker 1
2024-02-02 21:15:36 *** Starting uWSGI 2.0.20 (64bit) on [Fri Feb  2 20:15:20 2024] ***
2024-02-02 21:15:36 compiled with version: 9.4.0 on 22 July 2022 18:35:26
2024-02-02 21:15:36 os: Linux-5.15.0-1044-aws #49~20.04.1-Ubuntu SMP Mon Aug 21 17:09:32 UTC 2023
2024-02-02 21:15:36 nodename: green-liveweb12
2024-02-02 21:15:36 machine: x86_64
2024-02-02 21:15:36 clock source: unix
2024-02-02 21:15:36 pcre jit disabled
2024-02-02 21:15:36 detected number of CPU cores: 4
2024-02-02 21:15:36 current working directory: /home/xxx
2024-02-02 21:15:36 detected binary path: /usr/local/bin/uwsgi
2024-02-02 21:15:36 *** dumping internal routing table ***
2024-02-02 21:15:36 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2024-02-02 21:15:36 *** end of the internal routing table ***
2024-02-02 21:15:36 chdir() to /home/xxx/xxx
2024-02-02 21:15:36 your processes number limit is 256
2024-02-02 21:15:36 your memory page size is 4096 bytes
2024-02-02 21:15:36 detected max file descriptor number: 123456
2024-02-02 21:15:36 building mime-types dictionary from file /etc/mime.types...
2024-02-02 21:15:36 567 entry found
2024-02-02 21:15:36 lock engine: pthread robust mutexes
2024-02-02 21:15:36 thunder lock: disabled (you can enable it with --thunder-lock)
2024-02-02 21:15:36 uwsgi socket 0 bound to UNIX address /var/sockets/xx.pythonanywhere.com/socket fd 3
2024-02-02 21:15:36 Python version: 3.9.13 (main, Jul 22 2022, 17:05:13)  [GCC 9.4.0]
2024-02-02 21:15:36 *** Python threads support is disabled. You can enable it with --enable-threads ***
2024-02-02 21:15:36 Python main interpreter initialized at 0x555587a48d20
2024-02-02 21:15:36 your server socket listen backlog is limited to 100 connections
2024-02-02 21:15:36 your mercy for graceful operations on workers is 60 seconds
2024-02-02 21:15:36 setting request body buffering size to 65536 bytes
2024-02-02 21:15:36 mapped 334256 bytes (326 KB) for 1 cores
2024-02-02 21:15:36 *** Operational MODE: single process ***
2024-02-02 21:15:36 initialized 38 metrics
2024-02-02 21:15:36 WSGI app 0 (mountpoint='') ready in 14 seconds on interpreter 0x555587a48d20 pid: 1 (default app)
2024-02-02 21:15:36 *** uWSGI is running in multiple interpreter mode ***
2024-02-02 21:15:36 gracefully (RE)spawned uWSGI master process (pid: 1)
2024-02-02 21:15:36 spawned uWSGI worker 1 (pid: 12, cores: 1)
2024-02-02 21:15:36 metrics collector thread started
2024-02-02 21:15:36 spawned 2 offload threads for uWSGI worker 1
2024-02-02 21:16:06 Error running WSGI application
2024-02-02 21:16:06 RecursionError: maximum recursion depth exceeded while calling a Python object
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
2024-02-02 21:16:06     response = self.get_response(request)
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 140, in get_response
2024-02-02 21:16:06     response = self._middleware_chain(request)
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 57, in inner
2024-02-02 21:16:06     response = response_for_exception(request, exc)
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 142, in response_for_exception
2024-02-02 21:16:06     log_response(
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/site-packages/django/utils/log.py", line 241, in log_response
2024-02-02 21:16:06     getattr(logger, level)(
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/logging/__init__.py", line 1475, in error
2024-02-02 21:16:06     self._log(ERROR, msg, args, **kwargs)
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
2024-02-02 21:16:06     self.handle(record)
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/logging/__init__.py", line 1599, in handle
2024-02-02 21:16:06     self.callHandlers(record)
2024-02-02 21:16:06 
2024-02-02 21:16:06   File "/usr/local/lib/python3.9/logging/__init__.py", line 1661, in callHandlers
2024-02-02 21:16:06     hdlr.handle(record)
2024-02-02 21:16:06

And the access log at that time shows:

- - - [02/Feb/2024:20:14:21 +0000] "GET / HTTP/1.1" 499 0 "-" "python-requests/2.31.0" "-" response-time=60.060
- - - [02/Feb/2024:20:15:11 +0000] "GET / HTTP/1.1" 502 1661 "-" "python-requests/2.31.0" "-" response-time=10.708

It seems that you may have broken logging configuration for django. So when there is an error of some sort, it tries to log the error, but the broken logging config means that logging the error raises an error, which tries to log it etc.

Any suggestions on how I may have broken Django's logging configuration? Thank you.

Check the LOGGING dictionary in your Django settings.

Thanks, I didn't even have this on my settings... I have added it now and so far I haven't seen this error again, will keep an eye on it. Thanks again.

LOGGING = {
    "version":1,
    "disable_existing_loggers": False,
    }

Excellent, glad to hear that you got there in the end :-)

Hi, I'm getting a similar error using django, with a massive logging recursion problem on in production but not appearing in local. My app was working fine for the longest time, but I recently upgraded to django 3.2.25 and I only noticed the error these few days, and not sure if that was the cause.

I didn't use to have LOGGING in my settings file, but I've tried adding the code from bermejo (i.e. LOGGING = {"version": 1, ...}, but to no avail. Any tips on what I should do?

// example of what seems to cause it

2024-09-14 15:06:31 Error running WSGI application
2024-09-14 15:06:31 RecursionError: maximum recursion depth exceeded while calling a Python object

// snippet
2024-09-15 08:24:26,110:   File "/usr/lib/python3.7/logging/__init__.py", line 1586, in callHandlers
2024-09-15 08:24:26,111:     hdlr.handle(record)
2024-09-15 08:24:26,111: 
2024-09-15 08:24:26,112:   File "/usr/lib/python3.7/logging/__init__.py", line 894, in handle
2024-09-15 08:24:26,112:     self.emit(record)
2024-09-15 08:24:26,112: 
2024-09-15 08:24:26,113:   File "/usr/lib/python3.7/logging/__init__.py", line 1028, in emit
2024-09-15 08:24:26,113:     stream.write(msg + self.terminator)
2024-09-15 08:24:26,113: 
2024-09-15 08:24:26,114:   File "/usr/lib/python3.7/logging/__init__.py", line 1407, in error
2024-09-15 08:24:26,114:     self._log(ERROR, msg, args, **kwargs)
2024-09-15 08:24:26,114: 
2024-09-15 08:24:26,115:   File "/usr/lib/python3.7/logging/__init__.py", line 1514, in _log
2024-09-15 08:24:26,115:     self.handle(record)
2024-09-15 08:24:26,115: 
2024-09-15 08:24:26,116:   File "/usr/lib/python3.7/logging/__init__.py", line 1524, in handle
2024-09-15 08:24:26,116:     self.callHandlers(record)
2024-09-15 08:24:26,117: 
2024-09-15 08:24:26,117:   File "/usr/lib/python3.7/logging/__init__.py", line 1586, in callHandlers
2024-09-15 08:24:26,117:     hdlr.handle(record)
2024-09-15 08:24:26,118: 
2024-09-15 08:24:26,118:   File "/usr/lib/python3.7/logging/__init__.py", line 894, in handle
2024-09-15 08:24:26,118:     self.emit(record)
2024-09-15 08:24:26,119: 
2024-09-15 08:24:26,119:   File "/usr/lib/python3.7/logging/__init__.py", line 1028, in emit
2024-09-15 08:24:26,119:     stream.write(msg + self.terminator)
2024-09-15 08:24:26,120: 
2024-09-15 08:24:26,120:   File "/usr/lib/python3.7/logging/__init__.py", line 1407, in error
2024-09-15 08:24:26,121:     self._log(ERROR, msg, args, **kwargs)

@tangbj Are you calling django.setup somewhere in your code?

No I'm not

Were you able to identify specific url that, when requested, results in that error?

Hmm, it seems to be in the login page but I suspect any error triggers the recursion error

Ah I think I managed to solve it via the solution posted - https://www.pythonanywhere.com/forums/topic/31456/

Great! Glad you were able to work it out.