_cp_dispatch not getting called in cherrypy

泄露秘密 提交于 2019-12-10 19:46:36

问题


In the following example, I would expect to get an exception when accessing url http://127.0.0.1:8080/b/method_b. Instead, I get normal http response containing text 'method_b' in browser. No exception raised, meaning that _cp_dispatcher is not called. Am I getting something wrong about _cp_dispatch? I am using cherrypy version 3.8.0 in python 2.7.10

import cherrypy

class B(object):
    def _cp_dispatch(self, vpath):
        raise Exception("Here!!")

    @cherrypy.expose
    def method_b(self):
        return "method_b"

class A(object):
    def __init__(self):
        self.b = B()

cherrypy.quickstart(A())

回答1:


Yes you're getting something wrong about _cp_dispatch it will only be called when no property/method matches the request.

It will raise the exception if you call: http://127.0.0.1:8080/b/method_a.

method_a doesn't exists, method_b does.



来源:https://stackoverflow.com/questions/34289448/cp-dispatch-not-getting-called-in-cherrypy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!