Question

Hello here's my new trouble... i'm using pyramid and i have created a script to fill my db with initial data

I have a PasteDeploy configuration file (say development.ini) with this syntax

###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:shop_eshop]
use = egg:shop_eshop

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_debugtoolbar
    pyramid_tm

sqlalchemy.url = postgresql://eshop_db_user:testtest@localhost:5432/eshop_db

jinja2.directories = eshop:templates

ziggurat_foundations.model_locations.User = auth.models:User

# SESSION_BEAKER
session.type = file
session.data_dir = %(here)s/data/sessions/data
session.lock_dir = %(here)s/data/sessions/lock
session.key = s_key
session.secret = ...FBIRootAccessPW...
session.cookie_on_exception = true


[filter:fanstatic]
use = egg:fanstatic#fanstatic
recompute_hashes = false
versioning = true
bottom = True

publisher_signature = assets
compile = true
#in development
debug = true

[pipeline:main]
pipeline = fanstatic eshop

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, shop_eshop, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_shop_eshop]
level = DEBUG
handlers =
qualname = shop_eshop

[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

My script contains this piece of code that generates the error..

def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])

    setup_logging(config_uri)

    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    with transaction.manager:
        create_groups()
        create_users()

The error is thrown by this line

engine = engine_from_config(settings, 'sqlalchemy.')

If i remove the pipeline everything works correctly, i can't find a way to read the pipeline.

Here's my error

Traceback (most recent call last):
File "/srv/michael/e_shop/env/bin/fill_e_shop_db", line 9, in <module>
load_entry_point('e_shop==0.0', 'console_scripts', 'fill_e_shop_db')()
File "/srv/michael/e_shop/e_shop/e_shop/scripts/filldb.py", line 98, in main
engine = engine_from_config(settings, 'sqlalchemy.')
File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/__init__.py", line 350, in engine_from_config
KeyError: 'url'

Any suggestion? Thank you!

Was it helpful?

Solution

get_appsettings() is loading the settings for the main section of your ini file, unless otherwise specified. There are obviously no settings in that section. If you want to load the settings for a specific section then just specify that using the #. For example you should be able to run your program right now and get the result you want:

myprog development.ini#shop_eshop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top