ekansa/open-context-py

django.core.exceptions.ImproperlyConfigured: Set the ALLOWED_HOST environment variable

Closed this issue · 3 comments

Hello,

I am trying to set up opencontext-py on arch linux but run into following error.
Same error with debug false and ALLOWED_HOSTS ['*'] and python 3.4.3 or 2.7.9.

uWSGI log:

*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 11 16:38:55 2015] ***
compiled with version: 4.9.2 20150304 (prerelease) on 09 March 2015 22:14:49
os: Linux-3.18.6-1-ARCH #1 SMP PREEMPT Sat Feb 7 08:44:05 CET 2015
nodename: lugal
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /home/m/opencontext/oc-venv/web
writing pidfile to /home/m/opencontext/oc-venv/web/oc.pid
detected binary path: /home/m/opencontext/oc-venv/bin/uwsgi
chdir() to /home/m/opencontext/oc-venv/open-context-py
your processes number limit is 14378
your memory page size is 4096 bytes
detected max file descriptor number: 1024
VirtualHosting mode enabled.
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :1058 fd 3
uwsgi socket 1 bound to UNIX address /tmp/oc.sock fd 4
Python version: 3.4.3 (default, Feb 26 2015, 23:01:07)  [GCC 4.9.2 20150204 (prerelease)]
Set PythonHome to /home/m/opencontext/oc-venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xb9ebe0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145536 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
  File "./opencontext_py/settings.py", line 39, in get_secret
    return secrets[setting]
KeyError: 'ALLOWED_HOST'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./opencontext_py/wsgi.py", line 30, in <module>
    application = get_wsgi_application()
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/__init__.py", line 20, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/conf/__init__.py", line 46, in __getattr__
    self._setup(name)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/conf/__init__.py", line 94, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/m/opencontext/oc-venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "./opencontext_py/settings.py", line 67, in <module>
    added_host = get_secret('ALLOWED_HOST')
  File "./opencontext_py/settings.py", line 42, in get_secret
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the ALLOWED_HOST environment variable
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 15305)
spawned uWSGI worker 1 (pid: 15306, cores: 1)

and manage.py shell error:

(oc-venv)[m@lugal open-context-py]$ python manage.py shell
Traceback (most recent call last):
  File "/home/m/opencontext/oc-venv/open-context-py/opencontext_py/settings.py", line 39, in get_secret
    return secrets[setting]
KeyError: 'ALLOWED_HOST'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/core/management/base.py", line 330, in execute
    saved_locale = translation.get_language()
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 172, in get_language
    return _trans.get_language()
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 55, in __getattr__
    if settings.USE_I18N:
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/conf/__init__.py", line 46, in __getattr__
    self._setup(name)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/m/opencontext/oc-venv/lib/python3.4/site-packages/django/conf/__init__.py", line 94, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/m/opencontext/oc-venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/m/opencontext/oc-venv/open-context-py/opencontext_py/settings.py", line 67, in <module>
    added_host = get_secret('ALLOWED_HOST')
  File "/home/m/opencontext/oc-venv/open-context-py/opencontext_py/settings.py", line 42, in get_secret
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the ALLOWED_HOST environment variable.

Maybe someone experienced similar issues?
Thanks a million!

I see the issue. I need to update the sample "secrets.json" configuration. There are keys and values in that file that you need.

I'll update the code shortly.

OK. I updated the open-context-py/change-secrets.json file to reflect the new configuration needs. In your instance, you'll need to save the "change-secrets.json" as "secrets.json" and edit it to have all the values needed for your local setup.

You should also note that the only way to get data into this now is through Google/Open Refine or very specialized scripts to migrate data from the old Open Context. I haven't gotten around to developing a user interface for data entry yet (though if you feel up to doing it, I'd welcome help!!).

Thank you!
I have finally managed to import some testdata through openrefine but I had to fix some problems by hand because several Integrity Errors occurred:

IntegrityError at /imports/create-project
Integrityerror null value in column (published*) violates not-null constraint.

  • same error with short_id, view_group_id

For now I worked around this problem by changing the not-null contraint in the postgresql column.

Next error in the project creating process was

Exception Value: Can't convert 'UUID' object to str implicitly
Exception Location: ./opencontext_py/apps/imports/sources/views.py in create_project, line 42

Anyhow a project has been created where i was able to import data to.

I'll try to change my pgsql-db to en_US.UTF-8 because I think that could fix the problem?