Errors with esp32
sornen opened this issue · 5 comments
Micropython v1.20.0 and the latest Microdot produces a number of errors on a esp32 devkit:
With this code
from microdot import Microdot, Response
app = Microdot()
Response.default_content_type = 'text/html'
@app.route('/')
def index():
return 'Hello, world!'
app.run(debug=True)
the error is
Starting sync server on 0.0.0.0:5000...
<Request object at 3ffe84f0>
Traceback (most recent call last):
File "microdot.py", line 1212, in dispatch_request
TypeError: function takes 0 positional arguments but 1 were given
GET / 500
Also having a problem with microdot_asyncio
With this code
import uasyncio as asyncio
from microdot_asyncio import Microdot
app = Microdot()
@app.route('/')
async def index():
return 'Hello, world!'
async def main():
await app.start_server(debug=True)
asyncio.run(main())
the error is
Starting async server on 0.0.0.0:5000...
Traceback (most recent call last):
File "microdot_asyncio.py", line 370, in dispatch_request
File "microdot_asyncio.py", line 441, in _invoke_handler
TypeError: function takes 0 positional arguments but 1 were given
GET / 500
GET /favicon.ico 404
Your request handlers are incorrect. You need to accept the request object as an argument. Maybe you are too used to Flask. ;-)
Ah ok just found this out now and it is working. I was following the documentation in the supplied modules which does not show a request object.
Updated working code for future reference.
from microdot_asyncio import Microdot
app = Microdot()
@app.route('/')
async def index(request):
return 'Hello, world!'
app.run(debug=True)
Awesome project.
@sornen do you mean that my documentation is missing the request
argument? Where exactly?
for both microdot.py and microdot_asyncio.py the document strings for def run() show examples which are missing the request object. The documentation for microdot is fine in this regard, but I looked at the modules first and forgot there was excellent documentation that showed the correct call. My bad.
Thanks, I have fixed those examples now!