Trouble getting JSON-PRC to work with Python requests.
#1
Hi there. The folowing code just gets me all XBMC parameters instead of movies, what am i missing?
PHP Code:
import requests
import json


url 
"http://localhost:8080/jsonrpc"
headers = {'content-type''application/json'}

payload = {"jsonrpc""2.0""method""VideoLibrary.GetMovies""params": { "filter": {"field""playcount""operator""is""value""0"}, "limits": { "start" 0"end"75 }, "properties" : ["art""rating""thumbnail""playcount""file"], "sort": { "order""ascending""method""label""ignorearticle"'true' } }, "id""libMovies"}

    
requests.get(urlparams=payloadheaders=headers);
print(
r.json()); 
Reply
#2
You need to use HTTP POST or pass the JSONRPC request with the "request" parameter.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#3
Hi, Did you get this to work? Trying to do same thing
Thanks
Reply
#4
Haven't tried it myself, but looks promising: https://github.com/jcsaaddupuy/python-xbmc
Kodi Music Remote for iOS, the remote control for music lovers - http://kodimusicremote.com
Reply
#5
(2015-02-12, 07:19)Montellese Wrote: You need to use HTTP POST or pass the JSONRPC request with the "request" parameter.

Thank you Montellese for replying. I'm back from a quick 10 days vacation. I did a POST request and got a parse error.

Perhaps Python is playing with me?

Code:
import requests
import json


url = "http://localhost:8080/jsonrpc";
headers = {'content-type': 'application/json'};

payload = {"jsonrpc": "2.0",
           "method": "VideoLibrary.GetMovies",
           "params": {"filter": {"field": "playcount", "operator": "is", "value": "0"},
                      "limits": { "start" : 0, "end": 75 },
                      "properties" : ["art", "rating", "thumbnail", "playcount", "file"],
                      "sort": { "order": "ascending", "method": "label", "ignorearticle": 'true' } },
           "id": "libMovies"};


r = requests.post(url, data=payload, headers=headers);

print(r.json());

Returns:

Code:
{'jsonrpc': '2.0', 'id': None, 'error': {'code': -32700, 'message': 'Parse error.'}}
Reply
#6
your payload is invalid.

use http://jsonlint.com/ to validate
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#7
Just removed the single quotes on 'true' and replaced them by double quotes, was a typo, still getting the parse error.

The thing is, the same thing in NodeJS works.

Edit:

mmmh, checked how the url is assembled by Python Requests and got:

Code:
http://localhost:8080/jsonrpc?jsonrpc=2.0&id=libMovies&params=sort&params=properties&params=filter&params=limits&method=VideoLibrary.GetMovies

Looks like somehow the parameters are not passed by Requests.
Reply
#8
(2015-02-24, 23:56)GAZ082 Wrote: Just removed the single quotes on 'true' and replaced them by double quotes, was a typo, still getting the parse error.
There are no quotes of any kind around true/false.

(2015-02-24, 23:56)GAZ082 Wrote:
Code:
http://localhost:8080/jsonrpc?jsonrpc=2.0&id=libMovies&params=sort&params=properties&params=filter&params=limits&method=VideoLibrary.GetMovies

Looks like somehow the parameters are not passed by Requests.
Yup that looks completely wrong.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#9
Instead of using payload as a Python dictionary:

python:
payload = { "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "mybash"}

Use it as a single string:

python:
payload = '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "mybash"}'

Now the parse error is gone. I know this post is old, but maybe someone with a similar problem will benefit from it.
Reply

Logout Mark Read Team Forum Stats Members Help
Trouble getting JSON-PRC to work with Python requests.0