【问题标题】:Pyramid Auth error with Persona / BrowseridPersona / Browserid 的 Pyramid Auth 错误
【发布时间】:2014-02-17 12:26:53
【问题描述】:

我想在我的应用程序中使用角色或浏览器 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,))

我的初始化文件

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')

谢谢

【问题讨论】:

    标签: python pyramid browserid persona


    【解决方案1】:

    从此错误:

    Import error: No module named pyramid_persona
    

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

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

    将所有部分拼接在一起可能会有点复杂,因此我建议阅读 Ryan Kelly(在 Mozilla 工作)撰写的 this great writeup,其中展示了所有部分是如何连接在一起的。

    【讨论】:

    • 嗨,Burhan,回答我的坦克,我已经安装了,但是现在我在构建时遇到了很多错误,例如: KeyError: 'repoze.lru: package not found, WTF is repoze .lru?
    • 你有 setup.py 吗?看起来你错过了很多包。 repose.lru 是最近最少使用的缓存 API。我认为您需要确保您的设置一切正常。
    猜你喜欢
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多