Announcement Announcement Module
No announcement yet.
Spring Python trouble on running an example Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Python trouble on running an example

    Hello. I recently read 'Spring Python 1.1' by Greg L. Turnquist. to learn spring framework on python.
    While learning, I tried a few examples introduced in the book and I bumped into a trouble on chapter 8, "Case Study I - Intergrating Spring Python with your Web Application."

    And, I get this error below. I don't have a clue even on google..
    500 Internal Server Error

    The server encountered an unexpected condition which prevented it from fulfilling the request.

    Traceback (most recent call last): File "c:\Python27\lib\site-packages\cherrypy\", line 633, in respond self.namespaces(self.config) File "c:\Python27\lib\site-packages\cherrypy\lib\", line 115, in __call__ exit(None, None, None) File "c:\Python27\lib\site-packages\cherrypy\", line 446, in __exit__ tool = getattr(self, name) AttributeError: 'Toolbox' object has no attribute 'filterChainProxy'
    Powered by CherryPy 3.2.4
    I figured out that CherryPy doesn't have the attribute 'filterChainProxy' in However, the example code in below tries to use "tools.filterChainProxy.on" and that's the reason as far as i know.

    I cannot find any solution for this issue on google. Why in the first place the author made this code using tools.filterChainProxy? Was it supported back then, and now it's deprecated? Or, why else? I looked up in the documentation page of cherrypy and still no clue.

    Please help me with the code below (I put the related parts in red):
    import cherrypy
    import os
    from springpython.context import ApplicationContext
    from import *

    from ctx2 import *

    if __name__ == '__main__':
    cherrypy.config.update({'server.socket_port': 8009})

    ctx = ApplicationContext(SpringBankAppContext())

    SecurityContextHolder.setStrategy(SecurityContextH older.MODE_GLOBAL)

    conf = {"/": {"tools.sessions.on":True,


    from springpython.config import PythonConfig, Object
    from import *
    from import *
    from import *
    from import *
    from import *
    from import *

    from app2 import *

    class SpringBankAppContext(PythonConfig):
    def __init__(self):

    def view(self):
    view = SpringBankView()
    view.auth_provider = self.auth_provider()
    view.filter = self.auth_processing_filter()
    view.http_context_filter = self.httpSessionContextIntegrationFilter()
    return view

    def filterChainProxy(self):
    return CP3FilterChainProxy(filterInvocationDefinitionSour ce =
    ("/login.*", ["httpSessionContextIntegrationFilter"]),
    ("/.*", ["httpSessionContextIntegrationFilter",

    def httpSessionContextIntegrationFilter(self):
    filter = HttpSessionContextIntegrationFilter()
    filter.sessionStrategy = self.session_strategy()
    return filter

    def session_strategy(self):
    return CP3SessionStrategy()

    def exception_translation_filter(self):
    filter = ExceptionTranslationFilter()
    filter.authenticationEntryPoint = self.auth_filter_entry_pt()
    filter.accessDeniedHandler = self.accessDeniedHandler()
    return filter

    def auth_filter_entry_pt(self):
    filter = AuthenticationProcessingFilterEntryPoint()
    filter.loginFormUrl = "/login"
    filter.redirectStrategy = self.redirectStrategy()
    return filter

    def accessDeniedHandler(self):
    handler = SimpleAccessDeniedHandler()
    handler.errorPage = "/accessDenied"
    handler.redirectStrategy = self.redirectStrategy()
    return handler

    def redirectStrategy(self):
    return CP3RedirectStrategy()

    def auth_processing_filter(self):
    filter = AuthenticationProcessingFilter()
    filter.auth_manager = self.auth_manager()
    filter.alwaysReauthenticate = False
    return filter

    def auth_manager(self):
    auth_manager = AuthenticationManager()
    auth_manager.auth_providers = [self.auth_provider()]
    return auth_manager

    def auth_provider(self):
    provider = DaoAuthenticationProvider()
    provider.user_details_service = self.user_details_service()
    provider.password_encoder = PlaintextPasswordEncoder()
    return provider

    def user_details_service(self):
    user_details_service = InMemoryUserDetailsService()
    user_details_service.user_dict = {
    "alice": ("alicespassword",["ROLE_CUSTOMER"], True),
    "bob": ("bobspassword", ["ROLE_MGR"], True),
    "carol": ("carolspassword", ["ROLE_SUPERVISOR"], True)
    return user_details_service

    def filter_security_interceptor(self):
    filter = FilterSecurityInterceptor()
    filter.auth_manager = self.auth_manager()
    filter.access_decision_mgr = self.access_decision_mgr()
    filter.sessionStrategy = self.session_strategy()
    filter.obj_def_source = [
    return filter

    def access_decision_mgr(self):
    access_decision_mgr = AffirmativeBased()
    access_decision_mgr.allow_if_all_abstain = False
    access_decision_mgr.access_decision_voters = [RoleVoter()]
    return access_decision_mgr
    import cherrypy

    from import *
    from import *
    from import *

    class SpringBankView(object):

    def __init__(self):
    self.filter = None
    self.auth_provider = None
    self.http_context_filter = None

    def index(self):
    return """
    Welcome to SpringBank!
    <a href="logout">Logout</a href>

    def login(self, from_page="/", login="", password="", error_msg=""):
    if login != "" and password != "":
    self.attempt_auth(login, password)
    raise cherrypy.HTTPRedirect(from_page)
    except AuthenticationException, e:
    raise cherrypy.HTTPRedirect(
    "?login=%s&error_msg=Username/password failure"
    % login)

    return """
    <form method="POST" action="">
    <td><input type="text" name="login"
    <td><input type="password" name="password"/></td>
    <input type="hidden" name="from_page" value="%s"/><br/>
    <input type="submit"/>
    """ % (error_msg, login, from_page)

    def attempt_auth(self, username, password):
    token = UsernamePasswordAuthenticationToken(username, password)
    SecurityContextHolder.getContext().authentication = \

    def logout(self):
    raise cherrypy.HTTPRedirect("/")
    The full source code is found in the url:

    Thanks in advance!
    Last edited by Jin Choi; Dec 21st, 2013, 08:06 PM.

  • #2
    I resolved this problem myself outta several experiments and let me share it with you.
    Any issues while running the example demos are mostly from version conflicts.

    My platform is Ubuntu 13.10

    Try to use virtualenv if any possible.
    Python 2.7.x works fine with springpython 1.1.0.FINAL.
    CherryPy 3.1.2 is what the writer of the book uses, so try to install that specific version.
    Mysql server and client are fine for version 5.x
    Pyro seems fine with version of 3.x (I use 3.16)

    overall: (below is not for virualenv)
    $ pip install springpython==1.1.0.FINAL CherryPy==3.1.2 Pyro==3.16
    $ sudo apt-get -y install mysql-server mysql-client python-mysqldb
    Last edited by Jin Choi; Dec 27th, 2013, 10:15 AM.