Webinterface using wsgi
#1
I have a small webinterface addon of type wsgi. It doesn't work anymore since the update to Kodi 21 (tried on ubuntu and windows). Kodi crashes immediately when I try to access the webinterface on http://localhost:8080/addons/webinterface.helloworld/

The only line I can see in the kodi log is
2024-04-23 22:32:15.432 T:231      info <general>: -->HTTP Python WSGI Interpreter Initialized<--

The problem can be reproduced using the following minimal addon consisting of addon.xml and app.py

addon.xml:

<?xml version="1.0" encoding="UTF-8"?>
<addon id="webinterface.helloworld" version="1.0.0" name="Hello world webinterface" provider-name="Millencolin007">
  <requires>
    <import addon="xbmc.python" version="3.0.0"/>
    <import addon="xbmc.webinterface" version="1.0.0"/>
    <import addon="script.module.bottle" version="0.12.8"/>
  </requires>
  <extension point="xbmc.webinterface" type="wsgi" library="app.py" entry="app"/>
  <extension point="kodi.addon.metadata">
    <summary lang="en">Hello world web interface</summary>
    <description lang="en">Hello world web interface</description>
    <platform>all</platform>
  </extension>
</addon>


app.py:

from bottle import Bottle

app = Bottle()

@app.route('/')
def index():
    return "Index"
Reply
#2
I'm replying only to say that I can confirm this on Kodi 21 running on MacOS.  Let me see if I can get someone to take a look at this.
Reply
#3
I had my suspicions that the built-in WSGI server is broken. Not sure if it can be fixed soon. As a workaround you can create a service addon that will host your web UI using Python's built-in wsgiref server. The only tricky part is that your server must gracefully close when Kodi shuts down.
A minimal example:
Code:

from socketserver import ThreadingMixIn
from wsgiref.simple_server import WSGIRequestHandler, make_server, demo_app

from xbmc import Monitor


class ThreadedHandler(ThreadingMixIn, WSGIRequestHandler):
    daemon_threads = True
    timeout = 1


monitor = Monitor()
httpd = make_server('0.0.0.0', 8090, app=demo_app, handler_class=WSGIRequestHandler)
while not monitor.abortRequested():
    httpd.handle_request()

You need to replace demo_app with your own Bottle app.
Reply
#4
Thanks for the feedback.

As a workaround it was enough to switch the type of the addon from webinterface to service and adding the following line at the end of the app.py to start the bottle server

Code:
app.run(host='0.0.0.0', port=8090)

Obviously this is not as nice as having it integrated as a webinterface since I need to run it on a different port and bypasses authentication
Reply
#5
(2024-04-26, 18:48)Millencolin007 Wrote: Thanks for the feedback.

As a workaround it was enough to switch the type of the addon from webinterface to service and adding the following line at the end of the app.py to start the bottle server

Code:
app.run(host='0.0.0.0', port=8090)

Obviously this is not as nice as having it integrated as a webinterface since I need to run it on a different port and bypasses authentication
As I noted above, the problem with using this approach is that Kodi won't be able to gracefully terminate your web server. handle_request() in a loop with checking Kodi abort flag is the correct approach.

BTW, you can configure your own authentification if needed.
Reply

Logout Mark Read Team Forum Stats Members Help
Webinterface using wsgi0