【问题标题】:Mod wsgi issue regarding django apache[已解决]关于 django apache 的 Mod wsgi 问题
【发布时间】:2020-05-29 23:29:00
【问题描述】:

我一直被困在这个 django apache 部署中。当我尝试使用 linode(Linux 基础服务器)部署我的网页并尝试访问它时,我的网站一直显示这个 500 Internal Server 错误。它发生在我在我的 venv shell 中运行它之后。

$ sudo service apache2 restart

enter image description here

由于网页建议我查看日志文件,我确实这样做了,我发现我有 mod wsgi 问题。这是我的日志文件。

[Fri Feb 14 06:43:49.388284 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035] mod_wsgi (pid=26679): Target WSGI script '/home/harryghgim/django_project/django_project/wsgi.py' cannot be loaded as Python module.
[Fri Feb 14 06:43:49.388369 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035] mod_wsgi (pid=26679): Exception occurred processing WSGI script '/home/harryghgim/django_project/django_project/wsgi.py'.
[Fri Feb 14 06:43:49.388622 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035] Traceback (most recent call last):
[Fri Feb 14 06:43:49.388720 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/django_project/wsgi.py", line 16, in <module>
[Fri Feb 14 06:43:49.388726 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     application = get_wsgi_application()
[Fri Feb 14 06:43:49.388734 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/venv/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Feb 14 06:43:49.388739 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     django.setup(set_prefix=False)
[Fri Feb 14 06:43:49.388745 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/venv/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Fri Feb 14 06:43:49.388750 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri Feb 14 06:43:49.388757 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
[Fri Feb 14 06:43:49.388760 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     self._setup(name)
[Fri Feb 14 06:43:49.388766 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
[Fri Feb 14 06:43:49.388770 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     self._wrapped = Settings(settings_module)
[Fri Feb 14 06:43:49.388777 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
[Fri Feb 14 06:43:49.388781 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Fri Feb 14 06:43:49.388787 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Fri Feb 14 06:43:49.388790 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     return _bootstrap._gcd_import(name[level:], package, level)
[Fri Feb 14 06:43:49.388813 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Fri Feb 14 06:43:49.388820 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Fri Feb 14 06:43:49.388826 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
[Fri Feb 14 06:43:49.388832 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
[Fri Feb 14 06:43:49.388837 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
[Fri Feb 14 06:43:49.388843 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Fri Feb 14 06:43:49.388850 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/home/harryghgim/django_project/django_project/settings.py", line 17, in <module>
[Fri Feb 14 06:43:49.388853 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     config = json.load(config_file)
[Fri Feb 14 06:43:49.388859 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/usr/lib/python3.6/json/__init__.py", line 299, in load
[Fri Feb 14 06:43:49.388862 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
[Fri Feb 14 06:43:49.388867 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
[Fri Feb 14 06:43:49.388871 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     return _default_decoder.decode(s)
[Fri Feb 14 06:43:49.388876 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
[Fri Feb 14 06:43:49.388879 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
[Fri Feb 14 06:43:49.388886 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]   File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
[Fri Feb 14 06:43:49.388889 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035]     obj, end = self.scan_once(s, idx)
[Fri Feb 14 06:43:49.388909 2020] [wsgi:error] [pid 26679:tid 140324755478272] [remote 121.131.97.11:51035] json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 5 column 1 (char 129)

对于这么长的日志文件,我深表歉意。谁能告诉我如何解决这个问题?

编辑

这是我位于 /home/harryghgim/django_project/django_project/wsgi.py 的 wsgi.py 文件

""" WSGI config for django_project project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ """ 
import os from django.core.wsgi
import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 
application = get_wsgi_application()

这是我在 /etc/apache2/sites-available/django_project.conf 中的虚拟主机设置

Alias /static /home/harryghgim/django_project/static
<Directory /home/harryghgim/django_project/static>
        Require all granted
</Directory>

Alias /media /home/harryghgim/django_project/media
<Directory /home/harryghgim/django_project/media>
        Require all granted
</Directory>

<Directory /home/harryghgim/django_project/django_project>
        <Files wsgi.py>
        Require all granted
        </Files>
</Directory>

WSGIScriptAlias / /home/harryghgim/django_project/django_project/wsgi.py
WSGIDaemonProcess django_app python-path=/home/harryghgim/django_project python-home=/home/harryghgim/django_project/venv
WSGIProcessGroup django_app

我应该更改其中任何一个来解决问题吗?

编辑 #2

因为它给我带来了巨大的痛苦,我宁愿决定运行另一个用户名和服务器名称略有不同的 linux 服务器。我也有同样的问题。这一次我会尽量把它整理整齐。

[Sat Feb 15 06:55:00.657722 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046] mod_wsgi (pid=3546): Failed to exec Python script file '/home/djtu/django_project/django_project/wsgi.py'.
[Sat Feb 15 06:55:00.658894 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046] mod_wsgi (pid=3546): Exception occurred processing WSGI script '/home/djtu/django_project/django_project/wsgi.py'.
[Sat Feb 15 06:55:00.659151 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046] Traceback (most recent call last):
[Sat Feb 15 06:55:00.659254 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/django_project/wsgi.py", line 16, in <module>
[Sat Feb 15 06:55:00.659291 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     application = get_wsgi_application()
[Sat Feb 15 06:55:00.659319 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Sat Feb 15 06:55:00.659324 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     django.setup(set_prefix=False)
[Sat Feb 15 06:55:00.659331 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
[Sat Feb 15 06:55:00.659335 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Sat Feb 15 06:55:00.659341 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
[Sat Feb 15 06:55:00.659346 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     self._setup(name)
[Sat Feb 15 06:55:00.659351 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 63, in _setup
[Sat Feb 15 06:55:00.659355 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     self._wrapped = Settings(settings_module)
[Sat Feb 15 06:55:00.659361 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 142, in __init__
[Sat Feb 15 06:55:00.659365 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Sat Feb 15 06:55:00.659371 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
[Sat Feb 15 06:55:00.659375 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     return _bootstrap._gcd_import(name[level:], package, level)
[Sat Feb 15 06:55:00.659392 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Sat Feb 15 06:55:00.659398 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Sat Feb 15 06:55:00.659404 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
[Sat Feb 15 06:55:00.659409 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
[Sat Feb 15 06:55:00.659415 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
[Sat Feb 15 06:55:00.659420 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Sat Feb 15 06:55:00.659426 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/home/djtu/django_project/django_project/settings.py", line 17, in <module>
[Sat Feb 15 06:55:00.659430 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     config = json.load(config_file)
[Sat Feb 15 06:55:00.659435 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/usr/lib/python3.7/json/__init__.py", line 296, in load
[Sat Feb 15 06:55:00.659439 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
[Sat Feb 15 06:55:00.659444 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
[Sat Feb 15 06:55:00.659448 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     return _default_decoder.decode(s)
[Sat Feb 15 06:55:00.659453 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
[Sat Feb 15 06:55:00.659457 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
[Sat Feb 15 06:55:00.659462 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]   File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
[Sat Feb 15 06:55:00.659466 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046]     obj, end = self.scan_once(s, idx)
[Sat Feb 15 06:55:00.659484 2020] [wsgi:error] [pid 3546:tid 140028878067456] [remote 121.131.97.11:50046] json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 6 column 1 (char 130)
[Sat Feb 15 06:55:00.850305 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045] mod_wsgi (pid=3546): Failed to exec Python script file '/home/djtu/django_project/django_project/wsgi.py'.
[Sat Feb 15 06:55:00.850350 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045] mod_wsgi (pid=3546): Exception occurred processing WSGI script '/home/djtu/django_project/django_project/wsgi.py'.
[Sat Feb 15 06:55:00.850563 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045] Traceback (most recent call last):
[Sat Feb 15 06:55:00.850634 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/django_project/wsgi.py", line 16, in <module>
[Sat Feb 15 06:55:00.850639 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     application = get_wsgi_application()
[Sat Feb 15 06:55:00.850646 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Sat Feb 15 06:55:00.850663 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     django.setup(set_prefix=False)
[Sat Feb 15 06:55:00.850683 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
[Sat Feb 15 06:55:00.850687 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Sat Feb 15 06:55:00.850693 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
[Sat Feb 15 06:55:00.850697 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     self._setup(name)
[Sat Feb 15 06:55:00.850702 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 63, in _setup
[Sat Feb 15 06:55:00.850706 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     self._wrapped = Settings(settings_module)
[Sat Feb 15 06:55:00.850711 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 142, in __init__
[Sat Feb 15 06:55:00.850715 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Sat Feb 15 06:55:00.850721 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
[Sat Feb 15 06:55:00.850724 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     return _bootstrap._gcd_import(name[level:], package, level)
[Sat Feb 15 06:55:00.850730 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Sat Feb 15 06:55:00.850735 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Sat Feb 15 06:55:00.850741 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
[Sat Feb 15 06:55:00.850747 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
[Sat Feb 15 06:55:00.850752 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
[Sat Feb 15 06:55:00.850758 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Sat Feb 15 06:55:00.850763 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/home/djtu/django_project/django_project/settings.py", line 17, in <module>
[Sat Feb 15 06:55:00.850767 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     config = json.load(config_file)
[Sat Feb 15 06:55:00.850772 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/usr/lib/python3.7/json/__init__.py", line 296, in load
[Sat Feb 15 06:55:00.850776 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
[Sat Feb 15 06:55:00.850781 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
[Sat Feb 15 06:55:00.850785 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     return _default_decoder.decode(s)
[Sat Feb 15 06:55:00.850794 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
[Sat Feb 15 06:55:00.850798 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
[Sat Feb 15 06:55:00.850803 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]   File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
[Sat Feb 15 06:55:00.850807 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045]     obj, end = self.scan_once(s, idx)
[Sat Feb 15 06:55:00.850824 2020] [wsgi:error] [pid 3546:tid 140028760569600] [remote 121.131.97.11:50045] json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 6 column 1 (char 130)

我检查了项目文件夹权限和 www-data 的东西。这是我的代码。

djtu@dj-serv:~/django_project$ ls -la
total 228
drwxr-xr-x 8 djtu www-data   4096 Feb 15 06:13 .
drwxr-xr-x 7 djtu djtu       4096 Feb 15 06:55 ..
-rw-r--r-- 1 djtu djtu       6148 Feb 15 05:56 .DS_Store
drwxr-xr-x 6 djtu djtu       4096 Feb 15 05:56 blog
-rw-rw-r-- 1 djtu www-data 167936 Feb 15 06:13 db.sqlite3
drwxr-xr-x 3 djtu djtu       4096 Feb 15 06:48 django_project
-rw-r--r-- 1 djtu djtu        634 Feb 15 05:56 manage.py
drwxrwxr-x 3 djtu www-data   4096 Feb 15 05:56 media
-rw-r--r-- 1 djtu djtu      13994 Feb 15 05:56 posts.json
-rw-r--r-- 1 djtu djtu        624 Feb 15 05:56 requirements.txt
drwxrwxr-x 4 djtu djtu       4096 Feb 15 06:08 static
drwxr-xr-x 5 djtu djtu       4096 Feb 15 05:56 users
drwxrwxr-x 6 djtu djtu       4096 Feb 15 06:00 venv

我还检查了 mod_wsgi 是否已启用。这是屏幕截图。

mod wsgi enabled

为了以防万一,我还放了 manage.py 文件,看看文件是不是乱七八糟的。

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

我也在我的项目文件夹中做了python manage.py check,如下所示。

(venv) djtu@dj-serv:~/django_project$ python manage.py check
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/djtu/django_project/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/djtu/django_project/django_project/settings.py", line 17, in <module>
    config = json.load(config_file)
  File "/usr/lib/python3.7/json/__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 6 column 1 (char 130)

这是我的机器信息:Apache/2.4.41 (Ubuntu 19.10) 用于服务器和虚拟主机 Python 3.7.5 和 Django 3.0.2

请让我知道我在哪里搞砸了。谢谢。

已解决

我搞砸了 json 文件格式。我不应该在数据末尾加上逗号。取而代之的是,

{"key1":"value1", "key2":"value2", "key3":"value3",}

我设置如下。

{"key1":"value1", "key2":"value2", "key3":"value3"}

而且效果很好。感谢所有的cmets!

【问题讨论】:

  • 您的 wsgi 脚本未加载。检查 wsgi 文件路径并添加虚拟主机以向我们提供更多信息。
  • 进入项目目录并运行python manage.py check以排除django/mod_wsgi。
  • @Borut 嗨。我按照你说的做了,它显示了另一个很长的错误消息,从这个 Traceback 开始(最近一次调用最后一次):文件“manage.py”,第 21 行,在 main()
  • @PyMaster 你好。我很难理解你写的东西。我检查了 wsgi 文件路径,它显然在那里.. 你想让我告诉我我的虚拟主机是什么,还是我自己在我的机器上添加一些东西?对不起,愚蠢的问题
  • 按照 django 文档:docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi 使用 mod_wsgi 部署 django 项目。这将帮助您跟踪任何错误。

标签: python django python-3.x apache


【解决方案1】:

已解决

我搞砸了 json 文件格式。我不应该在数据末尾加上逗号。取而代之的是,

{"key1":"value1", "key2":"value2", "key3":"value3",}

我设置如下。

{"key1":"value1", "key2":"value2", "key3":"value3"}

而且效果很好。感谢所有的cmets!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 2011-01-21
    • 2015-10-21
    • 2012-02-16
    • 2011-03-04
    • 1970-01-01
    • 2011-11-24
    相关资源
    最近更新 更多