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 #10

Open
Amanimasila opened this issue Nov 11, 2018 · 3 comments
Open

Keyerror #10

Amanimasila opened this issue Nov 11, 2018 · 3 comments

Comments

@Amanimasila
Copy link

Traceback (most recent call last):
File "manage.py", line 9, in
from solarpi.app import create_app
File "/home/amani/Desktop/new/solarpi/solarpi/app.py", line 10, in
from solarpi.settings import ProdConfig
File "/home/amani/Desktop/new/solarpi/solarpi/settings.py", line 7, in
class Config(object):
File "/home/amani/Desktop/new/solarpi/solarpi/settings.py", line 8, in Config
SECRET_KEY = os_env['SOLARPI_SECRET']
File "/home/amani/Desktop/new/.venv/lib/python2.7/UserDict.py", line 40, in getitem
raise KeyError(key)
KeyError: 'SOLARPI_SECRET'

i generated the key but still am getting the same error, can anyone help?

@Amanimasila
Copy link
Author

setting file

import os

os_env = os.environ

class Config(object):
SECRET_KEY = os_env['SOLARPI_SECRET']
APP_DIR = os.path.abspath(os.path.dirname(file)) # This directory
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir))
BCRYPT_LOG_ROUNDS = 13
ASSETS_DEBUG = False
DEBUG_TB_ENABLED = False # Disable Debug toolbar
DEBUG_TB_INTERCEPT_REDIRECTS = False
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc.
SQLALCHEMY_TRACK_MODIFICATIONS = False

class ProdConfig(Config):
"""Production configuration."""
ENV = 'prod'
DEBUG = False
DB_NAME = 'app.db'
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
DEBUG_TB_ENABLED = False # Disable Debug toolbar
SENTRY_DNS = os_env.get('SENTRY_DNS', None)

class DevConfig(Config):
"""Development configuration."""
ENV = 'dev'
DEBUG = False
DB_NAME = 'dev.db'
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
DEBUG_TB_ENABLED = True
ASSETS_DEBUG = True # Don't bundle/minify static assets
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc.

class TestConfig(Config):
TESTING = True
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///dev.db'
BCRYPT_LOG_ROUNDS = 1 # For faster tests
WTF_CSRF_ENABLED = False # Allows form testing

@RgnDunes
Copy link

RgnDunes commented Dec 3, 2020

I'm not sure if I'm correct but I think you created your environment variable SOLARPI_SECRET in your local machine's environment but you are running your application through virtual environment venv you created so what this would do is it would search your environment variable SOLARPI_SECRET in your virtual environment but as your environment variable SOLARPI_SECRET is actually present in your local machine's environment it gives you error namely KeyError as it is unable to find SOLARPI_SECRET in your virtual environment variable.

@RgnDunes
Copy link

RgnDunes commented Dec 3, 2020

Refer this article to get a better insight of using virtual environment variables.

https://pypi.org/project/python-dotenv/

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

2 participants