[GH-ISSUE #348] found SyntaxError: invalid syntax in httpd error_log about venv/bin/activate on CentOS 7 #223

Closed
opened 2026-02-27 15:57:52 +03:00 by kerem · 7 comments
Owner

Originally created by @xujianhua1974 on GitHub (Jul 24, 2020).
Original GitHub issue: https://github.com/retspen/webvirtcloud/issues/348

I installed webvirtcloud under directory /home/pyprojects/webvirtcloud using apache httpd with wgsi module, without using nginx but found error in error_log about venv/bin/activate, and can't open the website http://serverip:6080. I configured webvirtcloud as a virtual host with a configuration file '/etc/httpd/conf.d/virtualhost_webvirtcloud.conf' running on apache httpd. I have created virtualenv in venv directory and installed pypi packages according to conf/requirements.txt with the same version specified by the conf/requirements.txt, and migrate the project sqlite3 database without errors.
I have installed other Django projects using apache httpd with wgsi module and they run good. I don't know why this webvirtcloud can't run good. I appreciate anyone's help.

Originally created by @xujianhua1974 on GitHub (Jul 24, 2020). Original GitHub issue: https://github.com/retspen/webvirtcloud/issues/348 I installed webvirtcloud under directory /home/pyprojects/webvirtcloud using apache httpd with wgsi module, without using nginx but found error in error_log about venv/bin/activate, and can't open the website http://serverip:6080. I configured webvirtcloud as a virtual host with a configuration file '/etc/httpd/conf.d/virtualhost_webvirtcloud.conf' running on apache httpd. I have created virtualenv in venv directory and installed pypi packages according to conf/requirements.txt with the same version specified by the conf/requirements.txt, and migrate the project sqlite3 database without errors. I have installed other Django projects using apache httpd with wgsi module and they run good. I don't know why this webvirtcloud can't run good. I appreciate anyone's help.
kerem closed this issue 2026-02-27 15:57:52 +03:00
Author
Owner

@catborise commented on GitHub (Jul 24, 2020):

please use code formatting to make it more readable

<!-- gh-comment-id:663653495 --> @catborise commented on GitHub (Jul 24, 2020): please use code formatting to make it more readable
Author
Owner

@xujianhua1974 commented on GitHub (Jul 25, 2020):

@catborise : thanks for your attention! please check these information I uploaded to guide me what possible root-cause may result in the error .

  1. Here is part of error_log about webvirtualcloud
    [Fri Jul 24 22:48:02.491588 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] mod_wsgi (pid=27863): Failed to exec Python script file '/home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py'.
    [Fri Jul 24 22:48:02.491714 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] mod_wsgi (pid=27863): Exception occurred processing WSGI script '/home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py'.
    [Fri Jul 24 22:48:02.491912 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] Traceback (most recent call last):
    [Fri Jul 24 22:48:02.491974 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] File "/home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py", line 16, in <module>
    [Fri Jul 24 22:48:02.491986 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] '/home/pyprojects/webvirtcloud/venv/bin/activate', 'exec'))
    [Fri Jul 24 22:48:02.492018 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] File "/home/pyprojects/webvirtcloud/venv/bin/activate", line 5
    [Fri Jul 24 22:48:02.492042 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] if [ "${BASH_SOURCE-}" == "$0" ]; then
    [Fri Jul 24 22:48:02.492093 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] ^
    [Fri Jul 24 22:48:02.492117 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] SyntaxError: invalid syntax

  2. Here is webvirtcloud/wsgi_custom.py modified with correct directory
    import os
    import sys
    from django.core.wsgi import get_wsgi_application
    exec(compile(open('/home/pyprojects/webvirtcloud/venv/bin/activate', "rb").read(), '/home/pyprojects/webvirtcloud/venv/bin/activate', 'exec'))
    sys.path.append('/home/pyprojects/webvirtcloud')
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webvirtcloud.settings')
    application = get_wsgi_application()

  3. Here is virtual host configuration /etc/httpd/conf.d/virtualhost_webvirtcloud.conf
    <VirtualHost *:6080>
    ServerName djsvr.comhead.com.cn
    ServerAlias comhead.com.cn
    ServerAdmin xujianhua@comhead.com.cn
    DocumentRoot /home/pyprojects/webvirtcloud
    Alias /static /home/pyprojects/webvirtcloud/static
    <Directory "/home/pyprojects/webvirtcloud/static">
    Require all granted
    </Directory>
    WSGIDaemonProcess webvirtcloud python-path=/home/pyprojects/webvirtcloud threads=2 maximum-requests=1000 display-name=webvirtcloud
    WSGIProcessGroup webvirtcloud
    WSGIScriptAlias / /home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py
    <Directory "/home/pyprojects/webvirtcloud/webvirtcloud">
    <Files "wsgi_custom.py">
    Require all granted
    </Files>
    </Directory>
    </VirtualHost>

<!-- gh-comment-id:663782624 --> @xujianhua1974 commented on GitHub (Jul 25, 2020): @catborise : thanks for your attention! please check these information I uploaded to guide me what possible root-cause may result in the error . 1. Here is part of error_log about webvirtualcloud `[Fri Jul 24 22:48:02.491588 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] mod_wsgi (pid=27863): Failed to exec Python script file '/home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py'.` `[Fri Jul 24 22:48:02.491714 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] mod_wsgi (pid=27863): Exception occurred processing WSGI script '/home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py'.` `[Fri Jul 24 22:48:02.491912 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] Traceback (most recent call last):` `[Fri Jul 24 22:48:02.491974 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] File "/home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py", line 16, in <module>` `[Fri Jul 24 22:48:02.491986 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] '/home/pyprojects/webvirtcloud/venv/bin/activate', 'exec'))` `[Fri Jul 24 22:48:02.492018 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] File "/home/pyprojects/webvirtcloud/venv/bin/activate", line 5` `[Fri Jul 24 22:48:02.492042 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] if [ "${BASH_SOURCE-}" == "$0" ]; then` `[Fri Jul 24 22:48:02.492093 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] ^` `[Fri Jul 24 22:48:02.492117 2020] [wsgi:error] [pid 27863] [remote 172.17.100.119:64919] SyntaxError: invalid syntax` 2. Here is webvirtcloud/wsgi_custom.py modified with correct directory ` import os` ` import sys` ` from django.core.wsgi import get_wsgi_application` ` exec(compile(open('/home/pyprojects/webvirtcloud/venv/bin/activate', "rb").read(), '/home/pyprojects/webvirtcloud/venv/bin/activate', 'exec'))` ` sys.path.append('/home/pyprojects/webvirtcloud')` ` os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webvirtcloud.settings')` ` application = get_wsgi_application()` 3. Here is virtual host configuration /etc/httpd/conf.d/virtualhost_webvirtcloud.conf `<VirtualHost *:6080>` ` ServerName djsvr.comhead.com.cn` ` ServerAlias comhead.com.cn` ` ServerAdmin xujianhua@comhead.com.cn ` ` DocumentRoot /home/pyprojects/webvirtcloud` ` Alias /static /home/pyprojects/webvirtcloud/static` ` <Directory "/home/pyprojects/webvirtcloud/static">` ` Require all granted` ` </Directory>` ` WSGIDaemonProcess webvirtcloud python-path=/home/pyprojects/webvirtcloud threads=2 maximum-requests=1000 display-name=webvirtcloud` ` WSGIProcessGroup webvirtcloud` ` WSGIScriptAlias / /home/pyprojects/webvirtcloud/webvirtcloud/wsgi_custom.py` ` <Directory "/home/pyprojects/webvirtcloud/webvirtcloud">` ` <Files "wsgi_custom.py">` ` Require all granted` ` </Files>` ` </Directory>` `</VirtualHost>`
Author
Owner

@catborise commented on GitHub (Jul 25, 2020):

why are you using wsgi_custom?

have you see this doc : https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi/
there is a snippet like that:

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonHome /path/to/venv
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

port 6080 is using for console access with no vnc.
gunicorn usually work with port 8000

<!-- gh-comment-id:663821945 --> @catborise commented on GitHub (Jul 25, 2020): why are you using wsgi_custom? have you see this doc : https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi/ there is a snippet like that: ``` WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py WSGIPythonHome /path/to/venv WSGIPythonPath /path/to/mysite.com <Directory /path/to/mysite.com/mysite> <Files wsgi.py> Require all granted </Files> </Directory> ``` port 6080 is using for console access with no vnc. gunicorn usually work with port 8000
Author
Owner

@xujianhua1974 commented on GitHub (Jul 25, 2020):

@catborise: thanks. I have seen the docment you mentioned, but is different from my scenario. In my scenario, I deployed 3 Django WSGI applications in the same Apache instance. Each WSGI application needs its own Python virtual environmentuse different each other. The WSGIPythonHome cannot be placed inside of the VirtualHost configuration because it applies to the whole Apache instance and not just the single VirtualHost according to mod_wsgi Documentation(release 4.7 [7.13.6 Embedded Mode (Multiple Applications)]), activation of the Python virtual environment needs to be performed in the WSGI script itself. So I used wsgi_custom.py (which is originated from webvirtcloud project code, and is suggested from webvirtcloud README.md as following:

#### Apache mod_wsgi configuration
WSGIDaemonProcess webvirtcloud threads=2 maximum-requests=1000 display-name=webvirtcloud
WSGIScriptAlias / /srv/webvirtcloud/webvirtcloud/wsgi_custom.py

<!-- gh-comment-id:663834962 --> @xujianhua1974 commented on GitHub (Jul 25, 2020): @catborise: thanks. I have seen the docment you mentioned, but is different from my scenario. In my scenario, I deployed 3 Django WSGI applications in the same Apache instance. Each WSGI application needs its own Python virtual environmentuse different each other. The WSGIPythonHome cannot be placed inside of the VirtualHost configuration because it applies to the whole Apache instance and not just the single VirtualHost according to mod_wsgi Documentation(release 4.7 [7.13.6 Embedded Mode (Multiple Applications)]), activation of the Python virtual environment needs to be performed in the WSGI script itself. So I used wsgi_custom.py (which is originated from webvirtcloud project code, and is suggested from webvirtcloud README.md as following: `#### Apache mod_wsgi configuration` `WSGIDaemonProcess webvirtcloud threads=2 maximum-requests=1000 display-name=webvirtcloud` `WSGIScriptAlias / /srv/webvirtcloud/webvirtcloud/wsgi_custom.py`
Author
Owner

@xujianhua1974 commented on GitHub (Jul 25, 2020):

@catborise: thanks. I have changed to use wsgi.py, and using 8000 port, and I can open the login page. But I entered default admin user and password, and got a Internal Server Error (code 500). I checked the httpd error_log, it reported an error about sqlite3 writing a readonly database.

[Sat Jul 25 10:03:03.183339 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] mod_wsgi (pid=18640): Exception occurred processing WSGI script '/home/pyprojects/webvirtcloud/webvirtcloud/wsgi.py'.
[Sat Jul 25 10:03:03.194523 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] Traceback (most recent call last):
[Sat Jul 25 10:03:03.194600 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] File "/home/pyprojects/webvirtcloud/venv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
[Sat Jul 25 10:03:03.194613 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] return self.cursor.execute(sql, params)
[Sat Jul 25 10:03:03.194635 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] File "/home/pyprojects/webvirtcloud/venv/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
[Sat Jul 25 10:03:03.194645 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] return Database.Cursor.execute(self, query, params)
[Sat Jul 25 10:03:03.194686 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] sqlite3.OperationalError: attempt to write a readonly database
[Sat Jul 25 10:03:03.194717 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602]
[Sat Jul 25 10:03:03.194727 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] The above exception was the direct cause of the following exception:

<!-- gh-comment-id:663838025 --> @xujianhua1974 commented on GitHub (Jul 25, 2020): @catborise: thanks. I have changed to use wsgi.py, and using 8000 port, and I can open the login page. But I entered default admin user and password, and got a Internal Server Error (code 500). I checked the httpd error_log, it reported an error about sqlite3 writing a readonly database. `[Sat Jul 25 10:03:03.183339 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] mod_wsgi (pid=18640): Exception occurred processing WSGI script '/home/pyprojects/webvirtcloud/webvirtcloud/wsgi.py'.` `[Sat Jul 25 10:03:03.194523 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] Traceback (most recent call last):` `[Sat Jul 25 10:03:03.194600 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] File "/home/pyprojects/webvirtcloud/venv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute` `[Sat Jul 25 10:03:03.194613 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] return self.cursor.execute(sql, params)` `[Sat Jul 25 10:03:03.194635 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] File "/home/pyprojects/webvirtcloud/venv/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute` `[Sat Jul 25 10:03:03.194645 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] return Database.Cursor.execute(self, query, params)` `[Sat Jul 25 10:03:03.194686 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] sqlite3.OperationalError: attempt to write a readonly database` `[Sat Jul 25 10:03:03.194717 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] ` `[Sat Jul 25 10:03:03.194727 2020] [wsgi:error] [pid 18640] [remote 172.16.10.3:37602] The above exception was the direct cause of the following exception:`
Author
Owner

@catborise commented on GitHub (Jul 25, 2020):

does httpd user has permission to write read webvirtcloud files? especially db.sqlite3?

for wsgi_custom :
https://stackoverflow.com/questions/25020451/no-activate-this-py-file-in-venv-pyvenv

<!-- gh-comment-id:663841692 --> @catborise commented on GitHub (Jul 25, 2020): does httpd user has permission to write read webvirtcloud files? especially db.sqlite3? for wsgi_custom : https://stackoverflow.com/questions/25020451/no-activate-this-py-file-in-venv-pyvenv
Author
Owner

@xujianhua1974 commented on GitHub (Jul 27, 2020):

@catborise: Thanks. I changed the webvirtcloud files ownership. And its work.

<!-- gh-comment-id:664133691 --> @xujianhua1974 commented on GitHub (Jul 27, 2020): @catborise: Thanks. I changed the webvirtcloud files ownership. And its work.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/webvirtcloud#223
No description provided.