5

Please help to provide any ideas to direct wsgi or apache to the correct sqlite3 library.

I was trying to deploy a website with basic modules and a "hello world" front page at a CentOS web server. However, internal server error was raised and only happens in web surfing (port 80) at www.example.com. The (port 8000) runs fine when "python3 manage.py runserver" is called (Django version: 2.2.2). Here above is the details of error, which is about the incorrect version of SQLite 3.8.3 or later is required (found 3.7.17).

I used to reinstall sqlite3 and not work. When changing the content of base.py to the following command, the hello world site can be reached while the admin page was malfunctional (it may be due to another issue...). But hard coding is not healthy...

if Database.sqlite_version_info < (3, 7, 3):

No matter in root environment and virtual environment, both python2 and python3 can open the sqlite3 with version 3.28.0

(venv) [root@...]# python
Python 2.7.5 (default, Apr  9 2019, 14:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.28.0'


(venv) [root@...]# python3
Python 3.6.8 (default, May  2 2019, 20:40:44)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.28.0'
>>>

the code related in httpd.conf is

=====
#<VirtualHost ip-address:80>
ServerName example.com
RewriteCond %{REQUEST_URI} ^/((sub_site/.*$)|(sub_site$))
RewriteRule ^ - [L]
WSGIProcessGroup newproject
WSGIDaemonProcess newproject python-home=/home/site/venv python-path=/home/site/project_name/ startup-timeout=15
WSGIPythonPath /home/site/venv/lib/python3.6/site-packages
WSGIPassAuthorization On
WSGIScriptAlias /sub_site "/home/site/project_name/project_name/wsgi.py"
       <Directory /home/site/project_name/project_name>
               <Files wsgi.py>
                       Require all granted
               </Files>
       </Directory>
#Static media, of course:
#Alias /donut/site_media/ /path/to/static/media/
Alias /media /home/site/project_name/media/
<Directory /home/site/project_name/media>
Order deny,allow
Allow from all
</Directory>
Alias /static /home/site/project_name/static/
<Directory /home/site/project_name/static>
Order deny,allow
Allow from all
</Directory>
====

when visit www.example.com/app it raised

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.


Here is the httpd log error details:

[wsgi:error] [pid 16968:tid 140448358127360] basedir /home/site/project_name
[wsgi:error] [pid 16968:tid 140448358127360] /home/site/project_name/static
 mod_wsgi (pid=16968): Failed to exec Python script file '/home/site/project_name/project_name/wsgi.py'.
 mod_wsgi (pid=16968): Exception occurred processing WSGI script '/home/site/project_name/project_name/wsgi.py'.
Traceback (most recent call last):
File "/home/site/project_name/project_name/wsgi.py", line 19, in <module>
application = get_wsgi_application()
File "/home/site/venv/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/site/venv/lib64/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/site/venv/lib64/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/site/venv/lib64/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/venv/lib64/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/site/venv/lib64/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/home/site/venv/lib64/python3.6/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/site/venv/lib64/python3.6/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/home/site/venv/lib64/python3.6/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/site/venv/lib64/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/site/venv/lib64/python3.6/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/site/venv/lib64/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/site/venv/lib64/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 66, in <module>
check_sqlite_version()
File "/home/site/venv/lib64/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 63, in check_sqlite_version
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
error django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
3
  • By the way, except the problem I addressed, above could be a reference if you wish to depoly a django web application at a sub directory of the web link under only mod_wsgi and apache. As a newbie, I used to debug for weeks of time to make it work. Good luck to you all too!
    – ronaldhaha
    Jun 10, 2019 at 13:48
  • Hi, could you please elaborate on this a bit more? I tried what you mentioned as the solution, I had a very similar problem but nothing worked. I tried installing sqlite globally but it doesn't work. "sqlite3.sqlite_version" shows > 3.8 but when wsgi runs it show < 3.8.2. Can you tell me the steps you used to fix it?
    – Wold
    Feb 25, 2021 at 8:24

1 Answer 1

7

This is an issue with Ubuntu/Debian dependencies, the python build in current stable is not up to date with Django 2.2's sqlite requirements. There are two solutions:

  1. The simple way is just to downgrade Django to 2.1.2 where the requirements are met by the OS packages

  2. Compile Python3 with the required sqlite dependency.

5
  • Thanks for your advices. Could you please explain further about the point 2? Actually, when I open python3 in either root or virtual environment, python3 could import the latest version (3.28.0) of sqlite3, as well as when running at standalone mode. I have no idea which python or sqlite3 is called by wsgi or apache.
    – ronaldhaha
    Jun 10, 2019 at 13:42
  • You are right that the build-in sqlite3 version of python3.6 is 3.17 originally (which is not new enough). Yet I managed to reconfigure and reinstall the sqlite3. Now sqlite3 is 3.28.0 when being called by python2.8 or python3.6 on centOS platform.
    – ronaldhaha
    Jun 10, 2019 at 13:56
  • @ronaldhaha hope this helps: charlesleifer.com/blog/… Jun 18, 2019 at 19:27
  • also just a thought but you could always deploy this inside of a docker container with a linux distro that has more up to date packages? just a thought Jun 18, 2019 at 19:28
  • Many thanks, It somehow solves as I called "import sqlite3" and checked its versions at views.py, it showed "3.28.0" at the deployed webpage.
    – ronaldhaha
    Jun 19, 2019 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.