i cant get litespeed django venv to wrok .

May 6, 2019 452 views
Django Ubuntu 18.04

I am using the Django OpenLiteSpeed One-Click app. I can't get OpenLiteSpeed beyond the example site.

I get 503 or it just keeps loading. In the log I get:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

All I need to do to break it is set the example to use Mysql.

If you change back to sqllite3 it works fine. I know it work because if i use the django test server "python manage.py runserver 0.0.0.0:8000" so the venv is setup correctly.

I have tried adding to the context:
PYTHONHOME=/usr/local/lsws/Example/venv/
LS_PYTHONBIN=/usr/local/lsws/Example/venv/bin/python
Any Ideas?

7 Answers

HI

How about keep PYTHONHOME=/usr/local/lsws/Example/venv/ only in the Environment?

Best

Hi,

Yes that was the 1 st thing I did. I just tried again and I get the same result.

Understood, we will try to reproduce it locally first and update you soon.

The only way I could get things to work was to remove PYTHONHOME=/usr/local/lsws/Example/venv/ then copy all my modules to /usr/local/lib/python3.6/dist-packages.
This is a work around and not using venv.

Hi,

Could you please provide a detail step for how to trigger/reproduce it ?

All I need to do to break it is set the example to use Mysql.

I set it to mysql , but it works on my test server.

Best regards,

Below are the steps to break it. I just tried this whit the same results. Can you provide the context of you tested and the settings.py. I would like to see it.

Here are the steps.

cd /usr/local/lsws/Example/

virtualenv -p python3 venv

source venv/bin/activate

pip install django

django-admin startproject testapp

vi testapp/testapp/settings.py

change
ALLOWED_HOSTS = ['*']

add
STATICURL = '/testapp/static/'
STATIC
ROOT = '/usr/local/lsws/Example/testapp/public/static'

cd testapp

mkdir -p public/static
python manage.py collectstatic

chown -R nobody:nogroup /usr/local/lsws/Example/testapp

Set up Context
Type = App Server

URI = /testapp/

Location = /usr/local/lsws/Example/testapp

Binary Path = /usr/local/lsws/fcgi-bin/lswsgi

Application Type = WSGI

save and recycle litespeed

goto http://xxxx/testapp/admin

test and it will work

edit Context add

Environment = PYTHONHOME=/usr/local/lsws/Example/venv/

save and recycle litespeed

test and it will work

Now for the fun.

vi testapp/testapp/settings.py

comment out the sqllite3.

add

DATABASES = {
'default': {
'NAME': 'testappdb',
'ENGINE': 'mysql.connector.django',
'USER': 'testuser',
'PASSWORD': 'testuser',
'HOST': '10.10.10.10',
'OPTIONS': {
'autocommit': True,
'charset': 'utf8mb4',
},
}
}

pip install django-mysql

pip install mysql-connector-python==8.0.5 (I use this version because the newer ones have too many problems)

test and it will give 503 or 500 or just spin.

python manage.py runserver 0.0.0.0:8000

goto http://xxxx:8000/testapp/admin

This will work.

Hi,

I followed your steps , however I noticed that you miss one conf

below context setting up "Application Type", the line "startup file" , could you please add this ?

testapp/wsgi.py

this is my settings.py , the part about DB

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django',
        'USER': 'django',
        'PASSWORD': '123456789',
        'HOST': 'localhost',
        'PORT': '',
        'OPTIONS': {
        'autocommit': True,
        'charset': 'utf8mb4',
    },
}

Did you run manage.py migrate?

no 500 or 503 error , however if I remove that startup file line , I do have 500 error

(venv) root@openlitespeed-django-s-1vcpu-1gb-ams3-01:/usr/local/lsws/Example/testapp# curl -I -XGET http://xxx.xxx.xxx/testapp/admin/
HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Location: /testapp/admin/login/?next=/testapp/admin/
Expires: Thu, 09 May 2019 13:40:58 GMT
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Content-Length: 0
Date: Thu, 09 May 2019 13:40:58 GMT
Server: LiteSpeed
Connection: Keep-Alive

Best regards,

Have another answer? Share your knowledge.