troublegum / micropyserver

MicroPyServer is a simple HTTP server for MicroPython projects.
MIT License
126 stars 33 forks source link

Error with arguments for handlers #3

Closed antonwantstosleep closed 3 years ago

antonwantstosleep commented 3 years ago

Hi!

In README examples you write:

def show_index(request):
    ''' main request handler '''
    server.send("THIS IS INDEX PAGE!")

def show_info(request, address):
    ''' info request handler '''
    server.send("Your IP:" + str(address))

but when the handler is called only 1 argument (request) is passed. And in show_info we get an error:

Error: Traceback (most recent call last):
  File "libs/micropyserver.py", line 62, in start
TypeError: function takes 2 positional arguments but 1 were given

To enable passing 2 arguments (request, address) to a handler you should change your 62 line from route["handler"](request) to route["handler"](request, address). And correct examples: all of the handlers should take 2 arguments. Or make address optional.

Thank you for your work!

troublegum commented 3 years ago

Fixed