pyramid 1.5.4 can't find user model

19 views
Skip to first unread message

Mazzaroth M.

unread,
Apr 11, 2015, 4:37:37 PM4/11/15
to python-so...@googlegroups.com
Hi all, I'm trying to integrate psa with a pyramid web app and I'm getting this error:

  File "/Users/hannam/src/git/gadfly_env/gadfly/gadfly/__init__.py", line 72, in main
    init_social(config, Base, DBSession)
  File "/Users/hannam/src/git/gadfly_env/lib/python2.7/site-packages/social/apps/pyramid_app/models.py", line 23, in init_social
    User = module_member(config[setting_name('USER_MODEL')])
  File "/Users/hannam/src/git/gadfly_env/lib/python2.7/site-packages/social/utils.py", line 23, in module_member
    module = import_module(mod)
  File "/Users/hannam/src/git/gadfly_env/lib/python2.7/site-packages/social/utils.py", line 17, in import_module
    __import__(name)
ImportError: No module named 'gadfly.models.auth

here's a chunk of my development.ini where I define :

SOCIAL_AUTH_TWITTER_KEY = '< hidden >'
SOCIAL_AUTH_TWITTER_SECRET = '<hidden>'

SOCIAL_AUTH_AUTHENTICATION_BACKENDS =
    social.backends.twitter.TwitterOAuth

SOCIAL_AUTH_USER_MODEL = 'gadfly.models.auth.User'

~~~~

and here is my main method where init_social() is called:

def main(global_config, **settings):
    settings["app_root"] = abspath(dirname(dirname(__file__)))
    initialize_sql(settings)
    
    authn_policy = AuthTktAuthenticationPolicy(
        settings.get("auth.secret"),
        callback=UserMgr.auth_groupfinder,
        hashalg="sha512",
        timeout=1200,
        reissue_time=300)
    authz_policy = ACLAuthorizationPolicy()

    session_factory = SignedCookieSessionFactory(settings.get("session.secret"))

    config = Configurator(settings=settings,
        root_factory="gadfly.RootFactory",
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory)

    config.set_request_factory(RequestWithUserAttribute)
    config = build_routes(config)
    config.add_renderer('jsonp', JSONP(param_name='callback'))
    config.registry['mailer'] = Mailer.from_settings(settings)

    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config.include("pyramid_mako")

    config.include('social.apps.pyramid_app')
    config.scan('social.apps.pyramid_app')

    from social.apps.pyramid_app.models import init_social
    init_social(config, Base, DBSession)

    config.add_static_view('static', 'static', cache_max_age=3600)

    config.scan("gadfly.views")
    return config.make_wsgi_app()

~~~~

I can confirm there is indeed a User class defined in the auth.py
`gadfly` is my root package > `models` package > auth.py

I don't know what I'm doing wrong here. Maybe User shouldn't be in auth.py? Not sure.

any help would be appreciated.

Mazzaroth M.

unread,
Apr 12, 2015, 1:18:23 PM4/12/15
to python-so...@googlegroups.com
I should also mention that other classes can access User by this import:

from gadfly.models.auth import User

without any issue.
Reply all
Reply to author
Forward
0 new messages