使用Persona / Browserid进行Pyramid Auth错误

时间:2014-02-17 12:26:53

标签: python pyramid browserid persona

我想在我的应用中使用角色或浏览器ID进行金字塔身份验证,问题是使用我们两个人时会看到错误。

当我使用角色时,控制台让我失望:

          Import error: No module named pyramid_persona

当我使用浏览器ID时,我没有名为browserid的模块

这是我的代码:

我的观看文件

        from pyramid.config import Configurator
        from pyramid.response import Response
        from pyramid.security import authenticated_userid

        #from waitress import serve
        from pyramid.config import Configurator
        from pyramid.response import Response
        from pyramid.security import authenticated_userid
        from pyramid.exceptions import Forbidden

def hello_world(request):
    userid = authenticated_userid(request)
    if userid is None:
        raise Forbidden()
    return Response('Hello %s!' % (userid,))

MY INIT FILE

from pyramid.config import Configurator
from resources import Root
import views
import pyramid_jinja2
import os
here = os.path.dirname(os.path.abspath(__file__))
settings={
    'persona.secret': 'some secret',
'persona.audiences': 'http://localhost:8080'
}
settings['mako.directories'] = os.path.join(here, 'templates')
__here__ = os.path.dirname(os.path.abspath(__file__))


def make_app():
    """ This function returns a Pyramid WSGI application.
    """
    settings = {}
    settings['mako.directories'] = os.path.join(__here__, 'templates')
    config = Configurator(root_factory=Root, settings=settings)
    config.include('pyramid_persona')////////////////////////THE ERROR AND TROUBLEMAKER
    config.add_renderer('.jinja2', pyramid_jinja2.Jinja2Renderer)
    config.add_view(views.my_view,
                    context=Root,
                    renderer='zodiac1.mako')
    #config.add_route( "home", "/home")
    #config.add_view(views.home_view, route_name="home", renderer="zodiac1.mako" )
    config.add_static_view(name='static',
                           path=os.path.join(__here__, 'static'))
   #    config.add_route('zodiac', '/zodiac')
    #    config.add_view(views.home_view, route_name='zodiac', #renderer='main.mako')
    #config.add_route('zodiac1', '/zodiac1')
    #config.add_view(views.home_view, route_name='zodiac1', renderer='zodiac1.mako')
    config.add_route('zodiac2', '/zodiac2')
    config.add_view(views.zodiac2_view, route_name='zodiac2', renderer='zodiac2.mako')
    config.add_route('zodiac3', '/zodiac3')
    config.add_view(views.guestbook, route_name='zodiac3', renderer='zodiac3.mako')
    config.add_route('hello', '/hello')
    config.add_view(views.guestbook, route_name='zodiac3', renderer='zodiac3.mako')

    return config.make_wsgi_app()

    application = make_app()

请告诉我我做错了什么,我确定它不喜欢我如何导入config.include('pyramid_persona')

由于

1 个答案:

答案 0 :(得分:0)

出现此错误:

Import error: No module named pyramid_persona

你可以告诉Python找不到pyramid_persona模块。也许是因为它没有安装。您应该使用pip install pyramid_persona安装它。

您还需要安装pyramid_whoauth才能获得BrowserID支持。

将所有部分拼接在一起会有点复杂,所以我建议阅读Ryan Kelly(在Mozilla工作)阅读this great writeup,了解所有部分是如何插在一起的。