My Django app works on my localhost but twice the server gave an error like this :
OSError at /
[Errno 5] Input/output error
Request Method: GET
Request URL: https://example.test/
Django Version: 4.2.11
Exception Type: OSError
Exception Value:
[Errno 5] Input/output error
Exception Location: /var/www/projectExample/application/custom_middleware.py, line 13, in __call__
Raised during: application.views.index
Python Executable: /var/www/projectExample/env/bin/python3.11
Python Version: 3.11.5
Python Path:
['/var/www/projectExample',
'/usr/lib/python311.zip',
'/usr/lib/python3.11',
'/usr/lib/python3.11/lib-dynload',
'/var/www/projectExample/env/lib/python3.11/site-packages']
Server time: Mon, 18 Mar 2024 09:24:18 +0530
Traceback Switch to copy-and-paste view
/var/www/projectExample/env/lib/python3.11/site-packages/django/core/handlers/exception.py, line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
Is there an issue with my code or is this purely a server OS error?
custom_middleware.py, line 13, in __call__
class CustomMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
print("*************** before the view is called ***************************************************")
print("Middleware: Custom code is running!")
print("request =", request)
# Code to run before the view is called
response = self.get_response(request)
print("*************** after the view is called (before the response is returned) *****************")
The middleware is probably calling the view function - because there isn’t a next middleware now. But on server restart, the app is working fine without any errors. So not sure where to debug.
Nothing of that sort. index() is just a return render() with print before it. print("request in index =", request)
I am using a middleware to get the currently logged in Active Directory user - using Microsoft AD for logging in.
@conditional_login_required
def index(request):
Exception Location: /var/www/projectExample/application/custom_middleware.py, line 13, in call
which is :
print("*************** before the view is called ***************************************************")
It goes away I get my sys-admin to restart the server (not the Azure server instance).
This is solved. I started using logger to also log whatever I was printing and one of the prints was logging in an object of a value which is not a string and hence it was failing to write to the cayank.log file. I removed that one particular logger line it’s all good now.
logger.debug("azureAD =", azureAD)
EDIT : I had copied the line from print and pasted in logger.debug - obviously it was and error because logger.debug’s second argument was incorrect and it was to be concatenated. My bad,