Forums

Error Running WSGI application

Hi, I am new to PythonAnywhere and I was trying to deploy my site and although it was working perfectly fine on the local host, I keep seeing a lot of errors in the server log and none of my pages can be viewed. Such as

2023-04-10 09:00:40 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",
2023-04-10 09:00:40 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",
2023-04-10 09:00:43 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",
2023-04-10 09:00:44 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",
2023-04-10 09:00:48 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",

 2023-04-10 09:00:49 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",

2023-04-10 09:00:49 Internal Server Error: /physics#012Traceback (most recent call last):#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner#012    response = get_response(request)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response#012    response = wrapped_callback(request, *callback_args, **callback_kwargs)#012  File "/home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py", line 287, in homepage_view_physics#012    return render(request, 'PhyHomePage.html', {'quote': quotes[int]})#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render#012    content = loader.render_to_string(template_name, context, request, using=using)#012  File "/home/GautamDas/.virtualenvs/storevirtual/lib/python3.10/site-packages/django/template/loader.py",

Along with that, I have also getting these errors which I have no idea why`

2023-04-10 09:02:38 Error running WSGI application
2023-04-10 09:02:38 RecursionError: maximum recursion depth exceeded while calling a Python object

Are you calling django.setup() somewhere in your code?

I don't think so.

Any idea how to fix this?

It looks like you don't have a virtualenv set up for your site right now; your website is configured to use one, but there isn't one at the specified location -- there should be an error showing on the "Web" page to highlight that. If you create a virtualenv using the version of Python that your site is configured to use, and then install Django and any other packages that you need into it, perhaps that will fix the problem?

I am already using a virtual environment for it:

(storevirtual) 01:26 ~/STOREFRONT/Django-PythonAnywhere (main)$ ls
Maria    Pipfile.lock  Templates  about.html  manage.py  playground  questions         runtime.txt  staticfiles  test.py
Pipfile  README.md     Tutors     db.sqlite3  myfolders  product     requirements.txt  static       storefront
(storevirtual) 01:26 ~/STOREFRONT/Django-PythonAnywhere (main)$

And I just checked by opening the virtual environment at the specified location, and the same one opened. I checked by installing the libraries in the requirements.txt file but all of them already exist.

I don't see any errors on the "Web" page

Could it be due to me using python 3.11.1 on my local host but using 3.10 here?

That's not impossible but unlikely. Did you reload your web app after making changes?

yeah i did

2023-04-13 05:22:41 RecursionError: maximum recursion depth exceeded while calling a Python object there is also this error which might be causing the issue, though I have no clue where its from and how to fix it

From the traceback, it looks like there is something that is causing the view at line 287 in /home/GautamDas/STOREFRONT/Django-PythonAnywhere/playground/views.py to be re-rendered whenever it is rendered. Perhaps there's a template tag in the template that does it. Perhaps it's a default page that is rendered on an error or something like that.

lines 285-287, is that not how you would normally render a template in django? quotes is a global array mentioned earlier in the code.

def homepage_view_physics(request):
int = random.randint(1,5)
return render(request, 'PhyHomePage.html', {'quote': quotes[int]})

Sure. That is how to render a template, but something else is causing the recursion.