Json Call to remote instance - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Json Call to remote instance (/showthread.php?tid=127759) Pages:
1
2
|
Json Call to remote instance - DecK - 2012-04-04 All I am trying to make a Json call to an instance of XBMC running on another machine on my network. Below is the code I am using. When I run this I get the following error. Any input would be appreciated. Error Message {"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"} PHP Code: import urllib RE: Json Call to remote instance - Bstrdsmkr - 2012-04-04 Looks like it didn't receive a valid JSON string. I think JSONRPC.Introspect requires a filter parameter. Try this: { "jsonrpc": "2.0", "method": "JSONRPC.Introspect", "params": { "filter": { "id": "AudioLibrary.GetSongs", "type": "method" } }, "id": 1 } RE: Json Call to remote instance - DecK - 2012-04-04 That gives me the exact same error message. In order to check the validity of the JSON strings, I ran both your and mine in an addon using xbmc.executeJSONRPC and both worked successfully. So it looks like the issue is somewhere else in the code. RE: Json Call to remote instance - Bstrdsmkr - 2012-04-05 Knew I should have waited and tested that lol try changing headers to: headers = {"Content-Type":"application/json"} That should only matter in pre-Frodo, but could be it. RE: Json Call to remote instance - DecK - 2012-04-05 Afraid not. :-( Still getting the same error. RE: Json Call to remote instance - jbel - 2012-04-05 I'm not too familiar with using the JSON API, however in your example code you are not POSTing JSON. You are incorrectly calling urlencode which creates a query string. You want to use json.dumps(values) for your data variable. RE: Json Call to remote instance - paddycarey - 2012-04-05 jbel's got it, this works: Code: import json RE: Json Call to remote instance - Bstrdsmkr - 2012-04-05 right, duh. I think you can also drop the user-agent as I'm pretty sure xbmc just ignores it RE: Json Call to remote instance - DecK - 2012-04-05 Thanks to everyone, It is working now. I've wrapped it into a function. Any suggestions for improved would still be appreciated. PHP Code: import json RE: Json Call to remote instance - Bstrdsmkr - 2012-04-05 You might change it to response = urllib2.urlopen(req) response = response.read() return json.loads(response) That way you get back actual objects instead of a string. I doubt you'll have a use for the string besides converting it to objects RE: Json Call to remote instance - djon - 2013-02-23 I keep getting a 401 Unauthorized. How do I send the user/password along to the remote instance? RE: Json Call to remote instance - pkscout - 2013-02-23 You can pass it as part of the URL. http://user:pass@HOST RE: Json Call to remote instance - djon - 2013-02-24 No that doesn't work here. I assume I need to send it as a parameter somehow, like with Curl, "-u" RE: Json Call to remote instance - djon - 2013-02-24 base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') req.add_header("Authorization", "Basic %s" % base64string) works. RE: Json Call to remote instance - schumi2004 - 2014-03-22 This looks exactly what i'm looking for. How can we use this for multiple hosts? |