Solved Query the database for beginners
#31
Thanks for taking the time from more important stuff to explain the obvious to a python virgin. Python 2.7 is not available on all platforms so simplejson is the best sometimes and we should still check the version?
Reply
#32
correct.
we did some timing experiment and from that we figured this out.
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
#33
Here's a little tip when using the JSON RPC: Define the query you're sending as a python dictionary and then convert it to a json object.

Do it like this:
PHP Code:
query_dict = {"jsonrpc""2.0""method""AudioLibrary.GetAlbumDetails""params": {"albumid"int(ALBUMDBID), "properties": ["artistid"]}, "id"1}
json_query xbmc.executeJSONRPC(json.dumps(query_dict)) 

Instead of this:
PHP Code:
json_query xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbumDetails", "params": {"albumid": %d, "properties": ["artistid"]}, "id": 1 }' int(ALBUMDBID)) 

This makes it easier to spot errors, and you don't have to deal with string formatting (this thing: '"albumid": %d' % int(ALBUMDBID)).


Also, you don't have to use 'has_key', instead just use 'in'. Like so:
PHP Code:
if 'result' in json_response and 'albumdetails' in json_response['result']: 
instead of
PHP Code:
if json_response.has_key('result') and (json_response['result'] != None) and json_response['result'].has_key('albumdetails'): 
Reply
#34
nice tips, thx!
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply

Logout Mark Read Team Forum Stats Members Help
Query the database for beginners0