'localhost: A server error occurred. Please contact the administrator
I am learning to run local hosts using Django with the help of https://www.dj4e.com/. I am currently trying to run the local server using the following:
python manage.py runserver
When I run this, the output given in terminal is the following:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:21:09
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
I clicked into 127.0.0.1:8000, but the server outputs the error in the title, A server error occurred. Please contact the administrator. My terminal also outputs the following error:
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:13:30] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:13:30] "GET /favicon.ico HTTP/1.1" 500 59
C:\Users\afrid\Desktop\Coding Projects\Django\mysite\mysite\settings.py changed, reloading.
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:13:55
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:00] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:00] "GET /favicon.ico HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Users\afrid\Desktop\Coding Projects\django\mysite\manage.py", line 22, in <module>
main()
File "C:\Users\afrid\Desktop\Coding Projects\django\mysite\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 363, in execute
settings.INSTALLED_APPS
File "C:\Python\Python310\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__
self._setup(name)
File "C:\Python\Python310\lib\site-packages\django\conf\__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python\Python310\lib\site-packages\django\conf\__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\afrid\Desktop\Coding Projects\django\mysite\mysite\settings.py", line 26, in <module>
DEBUG = FALSE
NameError: name 'FALSE' is not defined. Did you mean: 'False'?
PS C:\Users\afrid\Desktop\Coding Projects\django\mysite> python manage.py runserverpython manage.py runserver
Unknown command: 'runserverpython'. Did you mean runserver?
Type 'manage.py help' for usage.
PS C:\Users\afrid\Desktop\Coding Projects\django\mysite> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:14:24
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:29] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:29] "GET /favicon.ico HTTP/1.1" 500 59
C:\Users\afrid\Desktop\Coding Projects\Django\mysite\mysite\settings.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:15:47
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:15:49] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:15:50] "GET /favicon.ico HTTP/1.1" 500 59
C:\Users\afrid\Desktop\Coding Projects\Django\mysite\mysite\settings.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:16:04
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
[26/Feb/2022 15:16:07] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:16:07] "GET /favicon.ico HTTP/1.1" 500 59
PS C:\Users\afrid\Desktop\Coding Projects\django\mysite> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:21:09
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:22:49] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:22:49] "GET /favicon.ico HTTP/1.1" 500 59
I am not entirely sure what the issue is, I have already run all of the migrations and the admin user should already be set up.
Any help will be highly appreciated.
Solution 1:[1]
please have a look at the wsgi.py file ... the error message looks like you accidentally modified the get_wsgi_application line:
in wsgi.py:
# correct:
application = get_wsgi_application()
# in your case most certainly wrong:
application = get_wsgi_application
some explanation behind:
- first a Python thing (very superficially):
f = my_function # my_function is not called but stored in f
f = my_function() # my_function is called and the return value stored in f
# note: if my_thing is an object instantiated from a class
-> my_thing() will call the my_thing.__call()__ method
- WSGI Interface
the error messages shows the call "self.application(environ, start_response)" which is the WSGI standard related call to your Django app . This call should go to an object/function that can handle it, but it goes to get_wsgi_application() -> Type Error.
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
That means in your django app, "application" is not setup the right way before the first request via WSGI.
the WSGI Standard expects an object "application" that can be called with to parameters in order to route http requests to the Django-app:
application(environ, start_response)
This is provided by the code in wsgi.py:
application = get_wsgi_application()
which instantiates and stores a WSGIHandler Object in "application". If afterwards you make a call to "application" it is the same as calling
instance_of_WSGIHandler.__call__(... )
and if you have a look in django source code you will find the WSGIHandler classe
# file django.core.handlers.wsgi:
class WSGIHandler(base.BaseHandler):
request_class = WSGIRequest
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.load_middleware()
def __call__(self, environ, start_response):
# handle the http request from wsgi interface
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
