Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'SECRET_KEY‘ #275

Closed
IceRain00 opened this issue May 6, 2020 · 11 comments
Closed

KeyError: 'SECRET_KEY‘ #275

IceRain00 opened this issue May 6, 2020 · 11 comments
Assignees

Comments

@IceRain00
Copy link

when I nitialize Promgen using Docker: docker run --rm -it -v ~/.config/promgen:/etc/promgen/ line/promgen bootstrap,has the problem as follows:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/environ/environ.py", line 273, in get_value
    value = self.ENVIRON[var]
  File "/usr/local/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'SECRET_KEY'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/promgen", line 11, in <module>
    load_entry_point('promgen', 'console_scripts', 'promgen')()
  File "/usr/src/app/promgen/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 211, in fetch_command
    settings.INSTALLED_APPS
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/app/promgen/settings.py", line 39, in <module>
    SECRET_KEY = env.str("SECRET_KEY")
  File "/usr/local/lib/python3.6/site-packages/environ/environ.py", line 134, in str
    value = self.get_value(var, default=default)
  File "/usr/local/lib/python3.6/site-packages/environ/environ.py", line 277, in get_value
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable```

So what should I do to deal this problem 
@IceRain00
Copy link
Author

Can anyone provide a detailed installation steps?

@kfdm
Copy link
Collaborator

kfdm commented May 10, 2020

Last week was a holiday in Japan. I will try to triage this today

@kfdm
Copy link
Collaborator

kfdm commented May 11, 2020

Some of the bootstrap handling should be fixed in #270
Let me try to tag a new release this week.

@kfdm kfdm self-assigned this May 11, 2020
@kfdm
Copy link
Collaborator

kfdm commented May 14, 2020

I just released a new version of Promgen ( https://github.com/line/promgen/releases/tag/v0.47 ) can you give that a try and see if it works ?

@IceRain00
Copy link
Author

I build the docker image by the release code 0.47,then I do as README "Initialize Promgen"
docker run --rm -it -v ~/.config/promgen:/etc/promgen/ promgen:0.47 bootstrap.
The problem above did not appear,but has the problem as following:

/usr/src/app/promgen/__init__.py:30: UserWarning: Unset SECRET_KEY setting to random for now
  warnings.warn("Unset SECRET_KEY setting to random for now")
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 194, in get_new_connection
    conn = Database.connect(**conn_params)
sqlite3.OperationalError: unable to open database file
Traceback (most recent call last):
  File "/usr/local/bin/promgen", line 11, in <module>
    load_entry_point('promgen', 'console_scripts', 'promgen')()
  File "/usr/src/app/promgen/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
    self.check()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 76, in run_checks
    errors.extend(new_errors)
  File "/usr/src/app/promgen/checks.py", line 12, in sites
    if models.Site.objects.count() == 0:
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 392, in count
    return self.query.get_count(using=self.db)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 504, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 489, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1131, in execute_sql
    cursor = self.connection.cursor()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
    return self._cursor()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 194, in get_new_connection
    conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file

This maybe the problem of mysql config,but I set the config in docker-compose.yml as:

Database example: mysql://username:password@hostname/databasename

So can you provide a detailed dependency and installation description

@kfdm
Copy link
Collaborator

kfdm commented May 15, 2020

I'm sorry, can you try with https://github.com/line/promgen/releases/tag/v0.47.1 (there was a bug around some database checks in 0.47)

@IceRain00
Copy link
Author

Still has a problem when I run :
docker run --rm -it -v ~/.config/promgen:/etc/promgen/ promgen:0.47.1 bootstrap
there problem is as follow:

/usr/src/app/promgen/__init__.py:30: UserWarning: Unset SECRET_KEY setting to random for now
  warnings.warn("Unset SECRET_KEY setting to random for now")
System check identified some issues:

WARNINGS:
?: Missing setting for prometheus:blackbox in /etc/promgen/promgen.yml
?: Missing setting for prometheus:promtool in /etc/promgen/promgen.yml
?: Missing setting for prometheus:rules in /etc/promgen/promgen.yml
?: Missing setting for prometheus:targets in /etc/promgen/promgen.yml
Bootstrapping Promgen
Creating promgen config /etc/promgen/promgen.yml from /usr/src/app/promgen/tests/examples/promgen.yml
Traceback (most recent call last):
  File "/usr/local/bin/promgen", line 11, in <module>
    load_entry_point('promgen', 'console_scripts', 'promgen')()
  File "/usr/src/app/promgen/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/usr/src/app/promgen/management/commands/bootstrap.py", line 60, in handle
    shutil.copy(PROMGEN_CONFIG_DEFAULT, PROMGEN_CONFIG_FILE)
  File "/usr/local/lib/python3.6/shutil.py", line 245, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/local/lib/python3.6/shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/etc/promgen/promgen.yml'

@kfdm
Copy link
Collaborator

kfdm commented May 15, 2020

It looks like the container is unable to write to /etc/promgen/promgen.yml can you check the permissions there ?

@IceRain00
Copy link
Author

But I am the root user used on my developing machine,the core version of my machine is :

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"

@kfdm
Copy link
Collaborator

kfdm commented May 18, 2020

Perhaps you can try running with -u to change the user

-u, --user string Username or UID (format: <name|uid>[:<group|gid>])

Promgen is set to run as a non-root user (I think the uid defaults to 1000) but you can change it to a user on your local machine.

The error is showing that it can not write to ~/.config/promgen (which is mapped to /etc/promgen/ inside the container)

@kfdm kfdm closed this as completed Jan 18, 2021
@katelei6
Copy link

when I nitialize Promgen using Docker: docker run --rm -it -v ~/.config/promgen:/etc/promgen/ line/promgen bootstrap,has the problem as follows:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants