Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
eltomek
Posts: 12
Joined: Sat Feb 02, 2019 8:32 am

Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by eltomek » Sat Feb 02, 2019 8:40 am

Hi,
I am trying to launch a picoweb on micropython 1.10 with stocked uasyncio on my esp8266 board. I upload picoweb by ading them to the compiled package: micropython -m upip install -p modules picoweb
an then compiling and uploading the firmware to the board.
Everything works good until I try to launch any picoweb example, let's take this simple one: https://github.com/pfalcon/picoweb/blob ... webapp2.py

The only change is:
app.run(debug=True)
to
app.run(debug=True, host=station.ifconfig()[0])

The program starts with no issues but upon receiving first connection from the client I get:
Traceback (most recent call last):
File "main.py", line 46, in <module>
File "picoweb/__init__.py", line 298, in run
File "uasyncio/core.py", line 161, in run_forever
File "uasyncio/core.py", line 136, in run_forever
File "uasyncio/__init__.py", line 60, in remove_writer
TypeError: function takes 2 positional arguments but 3 were given
MicroPython v1.10 on 2019-02-02; ESP module with ESP8266
Type "help()" for more information.

Not sure how to move forward, any hints?

EDIT: pulled in the latest and greatest picoweb from https://github.com/pfalcon/picoweb and still get the same issue but captured some additional info:

* Running on http://192.168.0.87:8081/
INFO:picoweb:211.000 <HTTPRequest object at 3fff29b0> <StreamWriter <socket state=3 timeout=0 incoming=3fff95c8 off=23>> "GET /squares"
ERROR:picoweb:211.000 <HTTPRequest object at 3fff29b0> <StreamWriter <socket state=3 timeout=0 incoming=0 off=0>> ImportError("no module named 'utemplate'",)
Traceback (most recent call last):
File "picoweb/__init__.py", line 203, in _handle
File "main.py", line 37, in squares
File "picoweb/__init__.py", line 246, in render_template
File "picoweb/__init__.py", line 241, in _load_template
ImportError: no module named 'utemplate'
Traceback (most recent call last):
File "main.py", line 41, in <module>
File "picoweb/__init__.py", line 298, in run
File "uasyncio/core.py", line 161, in run_forever
File "uasyncio/core.py", line 136, in run_forever
File "uasyncio/__init__.py", line 60, in remove_writer
TypeError: function takes 2 positional arguments but 3 were given
MicroPython v1.10 on 2019-02-02; ESP module with ESP8266
Type "help()" for more information.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by pythoncoder » Sat Feb 02, 2019 9:17 am

What version of uasyncio are you running? I can't relate the line number in the traceback with any current version.

If you are running official MicroPython you need uasyncio V2.0 which is available here.

If you are running the @pfalcon "Pycopy" fork you need to use his fork of uasyncio which may be installed using upip or from here.

The simple solution is to use the latest release build of firmware (V1.9.10) which has uasyncio V2.0 built in.
Peter Hinch
Index to my micropython libraries.

eltomek
Posts: 12
Joined: Sat Feb 02, 2019 8:32 am

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by eltomek » Sat Feb 02, 2019 9:30 am

Thanks @pythoncoder.
Unfortunately, I compiled in the micropython-uasyncio 2.2.1 (micropython -m upip install -p modules micropython-uasyncio) but still get the same error:

* Running on http://192.168.0.87:8081/
INFO:picoweb:211.000 <HTTPRequest object at 3fff29b0> <StreamWriter <socket state=3 timeout=0 incoming=3fff95c8 off=23>> "GET /squares"
ERROR:picoweb:211.000 <HTTPRequest object at 3fff29b0> <StreamWriter <socket state=3 timeout=0 incoming=0 off=0>> ImportError("no module named 'utemplate'",)
Traceback (most recent call last):
File "picoweb/__init__.py", line 203, in _handle
File "main.py", line 37, in squares
File "picoweb/__init__.py", line 246, in render_template
File "picoweb/__init__.py", line 241, in _load_template
ImportError: no module named 'utemplate'
Traceback (most recent call last):
File "main.py", line 41, in <module>
File "picoweb/__init__.py", line 298, in run
File "uasyncio/core.py", line 161, in run_forever
File "uasyncio/core.py", line 136, in run_forever
File "uasyncio/__init__.py", line 60, in remove_writer
TypeError: function takes 2 positional arguments but 3 were given
MicroPython v1.10 on 2019-02-02; ESP module with ESP8266
Type "help()" for more information.


micropython -m upip install -p modules micropython-uasyncio
yields:
Installing to: modules/
Warning: pypi.org SSL certificate is not validated
Installing micropython-uasyncio 2.2.1 from https://files.pythonhosted.org/packages ... 2.1.tar.gz
Installing micropython-uasyncio.core 2.1 from https://files.pythonhosted.org/packages ... 2.1.tar.gz

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Library mismatch

Post by pythoncoder » Sat Feb 02, 2019 9:55 am

As I tried to explain above, if you want to use the @pfalcon version of uasyncio you'll need to compile from @pfalcon's 'Pycopy' source code.

Official MicroPython requires the official version of micropython-lib. This has uasyncio V2.0.
Peter Hinch
Index to my micropython libraries.

eltomek
Posts: 12
Joined: Sat Feb 02, 2019 8:32 am

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by eltomek » Sat Feb 02, 2019 10:42 am

Ok, I get it now, I was not aware that the PyPi.org hosted packages were @pfalcon ones.

This might me a stupid quesion but how do I get the official micropython-lib's uasyncio deployed to my micropython build? I don't want upip to download it from pypi.org but rather take the local one.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by kevinkk525 » Sat Feb 02, 2019 10:43 am

If you use an official micropython build, uasyncio is already on it.

If you use a daily build, you have to cross compile and copy it onto the device.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

eltomek
Posts: 12
Joined: Sat Feb 02, 2019 8:32 am

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by eltomek » Sat Feb 02, 2019 10:53 am

I compile the firmware from the source code as I want to include picoweb in the bundle. Copying micropython-lib/uasyncio and uasyncio-core to micropython-1.10/ports/esp8266/modules doesn't do the job, I guess some more sophisticated installation is needed for the micropython's makefile to pull the modules in.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by kevinkk525 » Sat Feb 02, 2019 11:27 am

That's exatly the process. Make sure to use the version from https://github.com/micropython/micropython-lib NOT the one from pfalcon/micropython-lib
If you want the official version for the official micropython version.
If you want to use pfalcon's version the process should be the same, just with his versions, but I don't know about bugs (wouldn't assume that there is one).
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

eltomek
Posts: 12
Joined: Sat Feb 02, 2019 8:32 am

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by eltomek » Sat Feb 02, 2019 9:32 pm

Seems like I'm not too lucky with that micropython stuff.
I compiled a pfalcon's pycopy (https://github.com/pfalcon/pycopy), pulled in (upip) the uasyncio, picoweb, micropython-ulogging (all pfalcon's AFAIK) and I still get the same issue report:

'192.168.0.87', '255.255.255.0', '192.168.0.1', '62.179.1.62')
Traceback (most recent call last):
File "main.py", line 67, in <module>
File "picoweb/__init__.py", line 298, in run
File "uasyncio/core.py", line 161, in run_forever
File "uasyncio/core.py", line 136, in run_forever
File "uasyncio/__init__.py", line 60, in remove_writer
TypeError: function takes 2 positional arguments but 3 were given
MicroPython v1.10-188-gf1644bca9 on 2019-02-02; ESP module with ESP8266
Type "help()" for more information.

Anyone could try it to confirm it works? What's even more, when running app with Debug=1 I additionally get:
ImportError: no module named 'logging'

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Problem with uasyncio running picoweb - TypeError: function takes 2 positional arguments but 3 were given

Post by kevinkk525 » Sat Feb 02, 2019 9:54 pm

I don't support pfalcon's fork for esp8266, only the mainstream one.
He might answer you directly @pfalcon
Or open an issue on his repository.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply