关于Openshift的Django - 500内部服务器错误 - wsgi.py中的错误

时间:2016-02-27 12:57:45

标签: python django openshift

我尝试在OpenShift上部署我的django应用程序,但有些错误,我不知道如何解决这个问题。

rhc tail -a myproject的结果: (并且网站页面显示500内部服务器错误)

[Sat Feb 27 07:23:32 2016] [notice] SIGHUP received.  Attempting to restart
[Sat Feb 27 07:23:32 2016] [notice] Digest: generating secret for digest authentication ...
[Sat Feb 27 07:23:32 2016] [notice] Digest: done
[Sat Feb 27 07:23:32 2016] [notice] Apache/2.2.15 (Unix) mod_wsgi/3.4 Python/3.3.2 configured -- resuming normal operations
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] mod_wsgi (pid=506177): Target WSGI script '/var/lib/openshift/56d067420c1e664f0e0000da/app-root/runtime/repo/wsgi.py' can
not be loaded as Python module.
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] mod_wsgi (pid=506177): Exception occurred processing WSGI script '/var/lib/openshift/56d067420c1e664f0e0000da/app-root/ru
ntime/repo/wsgi.py'.
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] Traceback (most recent call last):
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/app-root/runtime/repo/wsgi.py", line 10, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from myblog.wsgi import application
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/app-root/runtime/repo/myblog/wsgi.py", line 12, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from django.core.wsgi import get_wsgi_application
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/core/wsgi.py
", line 2, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from django.core.handlers.wsgi import WSGIHandler
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/core/handler
s/wsgi.py", line 10, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from django import http
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/http/__init_
_.py", line 2, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from django.http.request import (
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/http/request
.py", line 10, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from django.core import signing
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/core/signing
.py", line 51, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from django.utils.module_loading import import_string
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]   File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/utils/module
_loading.py", line 67, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1]     from importlib.util import find_spec as importlib_find
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] ImportError: cannot import name find_spec
1.194.187.34 - - [27/Feb/2016:07:25:08 -0500] "GET / HTTP/1.1" 500 618 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safa
ri/537.36"

这是我第一次在OpenShift(一个PaaS平台)上部署我的应用程序。 在此之前,我只使用centos(python3.5,django 1.9.2)在我的CVM上成功部署它。

我的文件是这样的:

myproject/
+---wsgi/
|   +---static/
|       +---.gitkeep
+---wsgi.py
+---setup.py
+---.openshift/ 
+---requirements.txt
+---myblog/
|   +----__init__.py
|   +----urls.py
|   +----settings.py
|   +----wsgi.py
+---+blog/
    +----__init__.py
    +----models.py
    +----views.py
    +----tests.py
    +----migrations
         +---__init__.py

的myproject / wsgi.py:

#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    exec(compile(open(virtualenv, 'rb').read(), virtualenv, 'exec'), dict(__file__=virtualenv))
except IOError:
    pass

from myblog.wsgi import application

的myproject / myblog / wsgi.py:

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings")
application = get_wsgi_application()

我的Django版本是最新的1.9.2,python 3.3由openshift提供。

感谢您关注我的问题并帮助我弄明白。

1 个答案:

答案 0 :(得分:2)

仅限Django 1.9 supports Python 3.4 or higher。您的特定错误是由find_spec added in Python 3.4的调用引起的。

您可以降级到Django 1.8或选择其他支持Python 3.4的PaaS提供商。