url = opts.pop('url') KeyError: 'url'

2,208 views
Skip to first unread message

Lukasz Szybalski

unread,
May 1, 2012, 11:42:52 PM5/1/12
to pylons-...@googlegroups.com
Hello,
In pyramid I'm trying to initialize a database model but I'm getting this error:


initialize_myapp_db development.ini
Traceback (most recent call last):
File "/home/lucas/tmp/pyramid/pyramid_env/bin/initialize_myapp_db",
line 9, in <module>
load_entry_point('myapp==0.0', 'console_scripts', 'initialize_myapp_db')()
File "/home/lucas/tmp/pyramid/myapp/myapp/scripts/initializedb.py",
line 30, in main
engine = engine_from_config(settings, 'sqlalchemy.')
File "/home/lucas/tmp/pyramid/pyramid_env/local/lib/python2.7/site-packages/SQLAlchemy-0.7.6-py2.7-linux-x86_64.egg/sqlalchemy/engine/__init__.py",
line 344, in engine_from_config
url = opts.pop('url')
KeyError: 'url'



my development.ini has

sqlalchemy.url = sqlite:///%(here)s/myapp.db

Any idea what this issue might be?

Thanks,
Lucas

Cornelius Kölbel

unread,
May 2, 2012, 12:43:41 AM5/2/12
to pylons-...@googlegroups.com
Hi Lucas,
I guess you are using the reserved word "URL" in your model. What does your model look like?
Kind regards
Cornelius
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>

John Anderson

unread,
May 2, 2012, 2:15:10 AM5/2/12
to pylons-...@googlegroups.com
Sounds like you might have configured a pipeline and renamed the app configuration to something other than main and now get_appsettings isn't pulling in the settings you need.

Try passing in your new app name on the command line, i.e  populate.py ./development.ini#appname

Lukasz Szybalski

unread,
May 2, 2012, 1:42:08 PM5/2/12
to pylons-...@googlegroups.com
You are correct.
In order to get toscawidget to work I needed to add PIPELINE at the
beginning of development.ini. (at least that is the only instructions
I found), as a result I needed to change the main app name to
something other then main.

I'll try the command above. Thank you.
Is there another way I can add toscawidget suppurt without renaming
the app name?

Thanks,
Lucas

Mike Orr

unread,
May 2, 2012, 11:02:34 PM5/2/12
to pylons-...@googlegroups.com
On Wed, May 2, 2012 at 10:42 AM, Lukasz Szybalski <szyb...@gmail.com> wrote:
> I'll try the command above. Thank you.
> Is there another way I can add toscawidget suppurt without renaming
> the app name?

The alternative would be not to use engine_from_config. Although this
points to a more general problem. Are any of your settings visible in
the application?

However, (and this is more a question for the Pyramid developers),
earlier versions of Pyramid used to use a pipeline by default, and
they could read the application settings. So there's some difference
between what they did and what you're doing. I've attached the
development.inii and __init__.py from Pyramid 1.0 in case it gives any
clues.

Pyramid tag 1.0
pyramid/paster_templates/routesalchemy/development.ini_tmpl
pyramid/paster_templates/routesalchemy/+package+/__init__.py_tmpl

--
Mike Orr <slugg...@gmail.com>
development.ini_tmpl
__init__.py_tmpl

Michael Merickel

unread,
May 2, 2012, 11:11:27 PM5/2/12
to pylons-...@googlegroups.com
On Wed, May 2, 2012 at 10:02 PM, Mike Orr <slugg...@gmail.com> wrote:
> However, (and this is more a question for the Pyramid developers),
> earlier versions of Pyramid used to use a pipeline by default, and
> they could read the application settings. So there's some difference
> between what they did and what you're doing.

In older versions there were no scripts shipped with the scaffolds
(initialize_db didn't exist). Thus the only entry point people used to
the app was via pserve which wants "main" by default, which was the
pipeline in older versions and is now the app. There is some
complexity in pyramid such that when you run proutes or pviews it's
able to find the pyramid application even if it's inside of a
pipeline, but get_appsettings() does not respect that behavior.

Bruce Coble

unread,
May 3, 2012, 1:23:24 AM5/3/12
to pylons-...@googlegroups.com
Hi Lucas,

Here is my development.ini for integrating toscawidgets (tw2) into a Pyramid application:

--------------------------------------------------------------------------------------------------------------------
[server:main]
use = egg:pyramid#wsgiref
host = localhost
port = 6543

[pipeline:main]
pipeline =
    egg:WebError#evalerror
    tw2.core
    pyramid

[filter:tw2.core]
use = egg:tw2.core#middleware

[app:pyramid]
use = egg:MyApp

# Pyramid config options
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = true
pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.default_locale_name = en
pyramid.includes = pyramid_debugtoolbar
                   pyramid_tm


# SQLAlchemy DB connection string
#sqlalchemy.url = sqlite:///%(here)s/myapp.db

# MySQL database URL
sqlalchemy.url = mysql://myusername:mypassword@localhost/myapp?charset=utf8

sqlalchemy.pool_recycle = 3600

# Location of Mako Templates (Not needed as of Pyramid-1.2.3, but saves adding "template/" to every view)
mako.directories = pulse:templates


   
# Begin logging configuration

[loggers]
keys = root, pulse, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_pulse]
level = DEBUG
handlers =
qualname = pulse

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither.  (Recommended for production systems.)

[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

# End logging configuration

---------------------------------------------------------------------------------------------------------------------------

Hope that helps.

Cheers,

Bruce

Lukasz Szybalski

unread,
May 22, 2012, 11:32:37 PM5/22/12
to pylons-...@googlegroups.com

Lukasz Szybalski

unread,
May 24, 2012, 11:27:08 AM5/24/12
to pylons-...@googlegroups.com
If the link didn't work for you before it should work now. (dns issue fixed)

The goal of this was to show how to create a widget using TW2, save it to a database, and then display results using datagrid tw2 widget, while doing everything as easy as copy/paste for a new user.

Thanks,
Lucas

Bruce Coble

unread,
May 24, 2012, 9:28:27 PM5/24/12
to pylons-...@googlegroups.com
Brilliant work Lucas!

Cheers,

Bruce Coble

Bruce Coble

unread,
May 24, 2012, 9:28:29 PM5/24/12
to pylons-...@googlegroups.com

John Anderson

unread,
Jun 26, 2012, 2:07:37 PM6/26/12
to pylons-...@googlegroups.com


On Tue, Jun 26, 2012 at 10:31 AM, Eugene Pustovit <logi...@gmail.com> wrote:
Hi guys, facing the same issue while trying to follow the official tutorial.
After trying to run the application with:
$ ../bin/pserve development.ini

getting the same KeyError 'URL' error message. Could you please help me with some kind of step by step instructions on how to fix this?
Thank you.

You either didn't include the 'sqlalchemy.url' key in your config (check spelling!)  or you renamed [app:main] to something else. 

John Anderson

unread,
Jun 26, 2012, 2:08:11 PM6/26/12
to pylons-...@googlegroups.com
On Tue, Jun 26, 2012 at 10:31 AM, Eugene Pustovit <logi...@gmail.com> wrote:
Hi guys, facing the same issue while trying to follow the official tutorial.
After trying to run the application with:
$ ../bin/pserve development.ini

getting the same KeyError 'URL' error message. Could you please help me with some kind of step by step instructions on how to fix this?
Thank you.

On Friday, May 25, 2012 4:28:29 AM UTC+3, Bruce Coble wrote:

Actually, I read your problem wrong.  Please provide us a stacktrace. 

Eugene Pustovit

unread,
Jun 26, 2012, 4:38:04 PM6/26/12
to pylons-...@googlegroups.com
Hi! Thank's for replying. Here's a stacktrace:

Traceback (most recent call last):
  File "/Users/logiartis/env/bin/pserve", line 8, in <module>
    load_entry_point('pyramid==1.3.2', 'console_scripts', 'pserve')()
  File "/Users/logiartis/env/lib/python2.7/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/scripts/pserve.py", line 47, in main
    return command.run()
  File "/Users/logiartis/env/lib/python2.7/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/scripts/pserve.py", line 290, in run
    relative_to=base, global_conf=vars)
  File "/Users/logiartis/env/lib/python2.7/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/scripts/pserve.py", line 318, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
  File "/Users/logiartis/env/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File "/Users/logiartis/env/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
    return context.create()
  File "/Users/logiartis/env/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/Users/logiartis/env/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
    return fix_call(context.object, context.global_conf, **context.local_conf)
  File "/Users/logiartis/env/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/util.py", line 56, in fix_call
    val = callable(*args, **kw)
  File "/Users/logiartis/logiprojects/Noname-Pilot/MyProject/myproject/__init__.py", line 9, in main
    engine = engine_from_config(settings, 'sqlalchemy.')
  File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/engine/__init__.py", line 355, in engine_from_config
KeyError: 'url'

Eugene Pustovit

unread,
Jun 27, 2012, 2:58:08 AM6/27/12
to pylons-...@googlegroups.com
And here's development.ini that I'm using:
[app:main]
use = egg:MyProject

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

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

# Begin logging configuration

[loggers]
keys = root, myproject

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_myproject]
level = DEBUG
handlers =
qualname = myproject

[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

# End logging configuration


John Anderson

unread,
Jun 27, 2012, 3:08:46 AM6/27/12
to pylons-...@googlegroups.com
You are missing sqlalchemy.url  in your config.  

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pylons-discuss/-/3RKQfBr0pncJ.

Eugene Pustovit

unread,
Jun 27, 2012, 4:27:45 PM6/27/12
to pylons-...@googlegroups.com
It worked. Thank you very much for your help!
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to pylons-discuss+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages