Search code examples
pythonwsgipythonanywhere

PythonAnywhere JSONDecodeError


I am attempting Codecademy's DjangoVet final module and am getting the below error in the error.log when I try and deploy via PythonAnywhere

2023-02-11 07:01:19,598: Error running WSGI application
2023-02-11 07:01:19,599: json.decoder.JSONDecodeError: Expecting ':' delimiter: line 2 column 18 (char 19)
2023-02-11 07:01:19,599:   File "/var/www/dollarbi11_pythonanywhere_com_wsgi.py", line 17, in <module>
2023-02-11 07:01:19,600:     application = get_wsgi_application()
2023-02-11 07:01:19,600: 
2023-02-11 07:01:19,600:   File "/home/DollarBi11/.virtualenvs/vet/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2023-02-11 07:01:19,600:     django.setup(set_prefix=False)
2023-02-11 07:01:19,600: 
2023-02-11 07:01:19,601:   File "/home/DollarBi11/.virtualenvs/vet/lib/python3.10/site-packages/django/__init__.py", line 19, in setup
2023-02-11 07:01:19,601:     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2023-02-11 07:01:19,601: 
2023-02-11 07:01:19,602:   File "/home/DollarBi11/.virtualenvs/vet/lib/python3.10/site-packages/django/conf/__init__.py", line 82, in __getattr__
2023-02-11 07:01:19,602:     self._setup(name)
2023-02-11 07:01:19,602: 
2023-02-11 07:01:19,602:   File "/home/DollarBi11/.virtualenvs/vet/lib/python3.10/site-packages/django/conf/__init__.py", line 69, in _setup
2023-02-11 07:01:19,603:     self._wrapped = Settings(settings_module)
2023-02-11 07:01:19,603: 
2023-02-11 07:01:19,603:   File "/home/DollarBi11/.virtualenvs/vet/lib/python3.10/site-packages/django/conf/__init__.py", line 170, in __init__
2023-02-11 07:01:19,603:     mod = importlib.import_module(self.SETTINGS_MODULE)
2023-02-11 07:01:19,603: 
2023-02-11 07:01:19,603:   File "/home/DollarBi11/djangovet/djangovet/settings.py", line 29, in <module>
2023-02-11 07:01:19,604:     project_keys = json.loads(k.read())
2023-02-11 07:01:19,604: 
2023-02-11 07:01:19,604:   File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
2023-02-11 07:01:19,604:     return _default_decoder.decode(s)
2023-02-11 07:01:19,604: 
2023-02-11 07:01:19,605:   File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
2023-02-11 07:01:19,605:     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
2023-02-11 07:01:19,605: 
2023-02-11 07:01:19,605:   File "/usr/local/lib/python3.10/json/decoder.py", line 353, in raw_decode
2023-02-11 07:01:19,605:     obj, end = self.scan_once(s, idx)

Here is the code for the dollarbi11_pythonanywhere_com_wsgi.py file, which I copied from the project tutorial

# +++++++++++ DJANGO +++++++++++
import os
import sys
#
## assuming your django settings file is at '/home/yourname/mysite/mysite/settings.py'
## and your manage.py is is at '/home/yourname/mysite/manage.py'
path = '/home/DollarBi11/djangovet'
if path not in sys.path:
    sys.path.append(path)
#
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangovet.settings'
#
## then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Lines 26 to 29 of settings.py

KEYSDIR = str(BASE_DIR)+"/keys.json"

with open(KEYSDIR) as k:
    project_keys = json.loads(k.read())

keys.json

{
    "SECRET_KEY" = "XXXX"
}

Solution

  • It looks like the problem is in your keys.json file; you should use colons rather than equals signs to separate keys and values, so it should be this:

    {
        "SECRET_KEY": "XXXX"
    }