Apache2 Django NameError: name "TypeError" is not defined

Viewed 2457

I am trying to run a django application on VPS via apache2, but I get the following in the website-error file, also 400(Bad Request):

Exception ignored in: <function Local.__del__ at 0x7f47273f48b0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined

I successfully ran a simple website that was made with "django-admin startproject" and could be viewed, but uploading project, made with the following skeleton, produces this error: https://django-project-skeleton.readthedocs.io/en/latest/apache2_vhost.html

I have tried including the python site-packages in the WSGIDaemon and by exluding them it produces the same effect.

In addition to this, I have also added:

<Directory /var/www/mysite/mysite>
        <Files wsgi.py>
            Require all granted
        </Files>
</Directory>

But again, no change

3 Answers

Because this post was upvoted and maybe it can help the others searching for that problem: this is my website.conf, just change example to your domain name. It also redirects to your https version of the website:

<VirtualHost *:80>    
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
    
</VirtualHost>

<VirtualHost *:443>    
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    # Insert the full path to the wsgi.py-file here
    WSGIScriptAlias /   /var/www/example/example/wsgi.py
   
    Alias /static/ /var/www/example/run/static/
    Alias /media/ /var/www/example/run/media/
 
    WSGIDaemonProcess   example python-path=/var/www/example

    # PROCESS_GROUP specifies a distinct name for the process group
    WSGIProcessGroup    example
    
    <Directory /var/www/example/example>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>
  
    <Directory /var/www/example/run/static>
        Require all granted
    </Directory>

    <Directory /var/www/example/run/media>
        Require all granted
    </Directory>

    LogLevel info

    ErrorLog    ${APACHE_LOG_DIR}/example_error.log
    CustomLog   ${APACHE_LOG_DIR}/example_access.log combined

    SSLEngine on
    SSLCertificateFile /var/ssl/example.crt
    SSLCertificateKeyFile /var/ssl/example.key
    SSLCertificateChainFile /var/ssl/example.ca-bundle

</VirtualHost>

Open your apache configuration's file then add "LogLevel info" inside the tag : VirtualHost at the end (before closing tag). It's works for me

I've encountered the same (ignored) exception in my apache2 error logs while running a functional application. It seems like you're using WSGI, so this ASGI-related python package shouldn't be the cause of your 400 error.

Related