pfalcon / picoweb

Really minimal web application framework for the Pycopy project (minimalist Python dialect) and its "uasyncio" async framework
https://github.com/pfalcon/pycopy
MIT License
510 stars 99 forks source link

Included examples may fail with "'module' object has no attribute '__path__'" on baremetal ports (e.g. ESP8266) #15

Open chrisb2 opened 7 years ago

chrisb2 commented 7 years ago

Environment: NodeMcu clone ESP8266 with picoweb built into custom firmware

  1. Copy _examplewebapp2.py to esp8266 and squares.tpl into templates dir
  2. Connect to network as station
  3. Add IP address as host parameter in last line of _examplewebapp2.py
  4. Reset
  5. At REPL: _import examplewebapp2.py
  6. From PC on network: http://ip-address-esp8266:8081/squares

Results in:

24.000 <HTTPRequest object at 3fff3e50> <StreamWriter <socket state=2 timeout=0 incoming=3fffac78 off=23>> "GET /squares"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "example_webapp2.py", line 24, in <module>
  File "picoweb/__init__.py", line 240, in run
  File "uasyncio/core.py", line 121, in run_forever
  File "uasyncio/core.py", line 85, in run_forever
  File "picoweb/__init__.py", line 156, in _handle
  File "example_webapp2.py", line 18, in squares
  File "picoweb/__init__.py", line 194, in render_template
  File "picoweb/__init__.py", line 190, in _load_template
  File "utemplate/source.py", line 153, in __init__
AttributeError: 'module' object has no attribute '__path__'

Work-around: Update: app = picoweb.WebApp(__name__) To: app = picoweb.WebApp(None)

GHPS commented 5 years ago

I had the same problem with the latest release version of picoweb under MicroPython 1.10 on an ESP32. So the problem is still there...

The work-around (deleting the reference to __name__) worked fine though it took me a while to find this issue report and the solution.