0

I'm trying to write a script that will run the 'update library' command on my XBMC.

When I try to run:

url = 'http://root:libreelec@%IP_ADDRESS%:12345/jsonrpc?request={"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}'
r = requests.get(url)

I see that the library is been updated but I'm getting the following error:

Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\Python27\lib\site-packages\requests\api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 473, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))

I have tried to modify the code to:

    url = 'http://root:libreelec@%IP_ADDRESS%:12345/jsonrpc?'
    data = json.dumps({"request": {"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}})
    r = requests.get(url, params=data)

but it doesn't seems to work, meaning I don't see the library updated.

What I'm doing wrong?

shlomiLan
  • 659
  • 1
  • 9
  • 33

1 Answers1

2

Who 'root' in the URL? Everything is much simple:

url = 'http://libreelec:12345/jsonrpc'
data = {"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "1"}
r = requests.post(url, json=data)

The /json endpoint accepts POST as well, and request.post will process a dict into a proper JSON request for you.

Roman Miroshnychenko
  • 1,496
  • 1
  • 10
  • 16
  • I'm still getting the same result, XBMC library is been updated and also I get the error message. any ideas? – shlomiLan Nov 17 '16 at 23:43
  • I forgot about "id" parameter (blindly copy-pasted JSON from your post). Now the JSON payload is correct, but I cannot tell about other parts like Kodi settings (you need to enable remote controlling of Kodi) or JSON-RPC endpoint address. You should check those yourself. – Roman Miroshnychenko Nov 18 '16 at 14:06