On Aug 14, 8:13 am, Peter Hartmann <
mailbox....@gmail.com> wrote:
> Hello there,
> truth is, I was not using Pylons since 0.9.7, but this piece of
> documentation still seems relevant:
>
>
http://pylonshq.com/docs/en/1.0/configuration/#getting-information-fr...
>
> So I have an auth.py file in /config which sets up, well, auth. It
> takes three parameters from ini, auth.secret being the first. I call
> it with config['auth.secret']. Of course, I ensured to put it in
> development ini. But config dictionary doesn't read it. Here's
> relevant portion of traceback:
>
> File "S:\share\projects\sources\myproject\myproject\config\auth.py",
> line 17, in auth_midd
> leware
> secret = config['auth.secret'],
> File "c:\pylons\lib\site-packages\paste-1.7.4-py2.5.egg\paste
> \registry.py", li
> ne 146, in __getitem__
> return self._current_obj()[key]
> KeyError: 'auth.secret'
When is auth_middleware being called?
If I were you, I'd pass the `config` object that's returned from
`load_environment` to the `auth_middleware` function instead of using
`pylons.config`. Also, instead of passing the whole `config` object, I
might jst pass just the values from `config` that are needed into
`auth_middleware`.
> Here's what is in config dict just before the call:
>
> {'pylons.app_globals': None,
> 'pylons.request_options': {'errors': 'replace',
> 'decode_param_names': False,
> 'charset': 'utf-8',
> 'language': 'en-us'},
> 'pylons.paths': {'controllers': None,
> 'templates': [],
> 'static_files': None,
> 'root': None},
> 'pylons.environ_config': {'session': 'beaker.session',
> 'cache': 'beaker.cache'},
> 'pylons.strict_tmpl_context': True,
> 'pylons.h': None,
> 'pylons.package': None, '
> debug': False,
> 'pylons.response_options': {'headers': {'Pragma': 'no-cache',
> 'Cache-
> Control': 'no-cache'},
> 'errors': 'strict',
> 'charset': 'utf-8',
> 'content_type': 'text/html'},
> 'pylons.tmpl_context_attach_args': False}
At the point where you're trying to use `pylons.config`, you're using
a sort of dummy version that hasn't been fully initialized. If you
call `auth_middleware` after `load_environment` runs and pass the
`config` returned from `load_environment` to `auth_middleware`, that
should fix your problem.
In general, I'd say that `pylons.config` should only be used in a
request context.