Marc Maxmeister
Marc Maxmeister

Reputation: 4689

CherryPy: What would the html command line syntax be if you wanted to pass a dictionary as an argument?

So I built a simple cherrypy function called 'echo' to try and figure out what cherrypy sends to my python function. Example:

http://djotjog.com/cp/echo/692-gg_org_id-2013-02-05.json/
RETURNS:
{'kw': {}, 'args': (), 'param_1': '692-gg_org_id-2013-02-05.json', 'param_2': None}

Now, this may seem weird, but I would like to pass a dictionary. Is this a html nightmare to do? Example:

this function needs two arguments. the params are optional:

def some_function(filename, params = {'db':'bh-localhost','h':'sparse','branching':7})

sending through cherrypy...

http://djotjog.com/cp/echo/692-gg_org_id-2013-02-05.json/{h:'branchy','branching':7,'db':'bh-localhost'}
RETURNS    
{'kw': {}, 'args': (), 'param_1': '692-gg_org_id-2013-02-05.json', 'param_2': "{h:'branchy','branching':7,'db':'bh-localhost'}"}

But when I pass through through the actual function and not the echo, it tells me:

404 Not found. Nothing matches the given URI.

Is this because the dictionary is a string and not a dict now? What trick can I do to pass a dictionary? Or just keep this to individual arguments?

Upvotes: 0

Views: 614

Answers (1)

Andrew Kloos
Andrew Kloos

Reputation: 4578

Try setting echo to receive a variable number of parameters...

@cherrypy.expose
def echo(self, *args, **kwargs):
    return kwargs['param_1']

Hope this helps.

Andrew

Upvotes: 1

Related Questions