CherryPy POST Request with Parameters, 400 response

Lately I've been setting up a simple HTTP web service using CherryPy (I've simplified the code):

from controllers import MyController
import cherrypy

if __name__ == '__main__':
    server_config = {
        'server.socket_host': '',
        'server.socket_port': 60000

    cherrypy.tree.mount(MyController(), '/Home', {})

where MyController has an Index method:

class MyController:
    def Index(self):

and I was calling the service from Python using the requests library:

requests.get('http://localhost:60000/Home/Index', data={'name': 'foo'})

but when I changed the request to use POST:'http://localhost:60000/Home/Index', data={'name': 'foo'})

my Index method was no longer being called; the service was returning a 400 error. Thanks to this answer I tried adding **kwargs to my service method:

class MyController:
    def Index(self, **kwargs):

and the Index method was now being called! That fixed the problem.


Leave a comment

What color are brown eyes? (spam prevention)
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.