Assistance converting Python 2 to 3 in an addon
#1
Lightbulb 
Hi there!

I have an add-on that I have been working on, to convert from Python 2, and it is almost working with Kodi 19, but I am suck on one line...  I think the one line, anyways.  I am not a developer, nor am I that familiar with  Python 3 :-)  I just plodded through, using errors and google searches to get the add-on to work up to this point.

The code chunk is:

json_query = \
            xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "VideoLibrary.Clean","id": 1 }'

json_query = unicode(json_query, 'utf-8', errors='ignore')  ##<--  This line is offending line
json_query = jsoninterface.loads(json_query) 
if json_query.has_key('result'):
     dbglog('Clean library sucessfully called')


Now I know that Python 3, you use str instead of unicode, since the queries are all encoded.  However, when I do that and use 

json_query = str(json_query, 'utf-8', errors='ignore')

I get the error:

json_query = str(json_query, 'utf-8', errors='ignore')
TypeError: decoding str is not supported


If I remove the offending line completely, I get the following error:

if json_query.has_key('result'):
                                                   AttributeError: 'dict' object has no attribute 'has_key'
                                                   -->End of Python script error report<--

Any help would be appreciated. The full code base cane be seen here:
https://pastebin.com/YxMC6sw7

Thanks!
Ken
Reply
#2
you should indeed remove that line, it isn't needed anymore in py3.

as for the error, 'has_key()' has been removed in python 3,
you can replace it with if 'result' in json_query:
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
#3
(2021-05-13, 10:49)ronie Wrote: you should indeed remove that line, it isn't needed anymore in py3.

as for the error, 'has_key()' has been removed in python 3,
you can replace it with if 'result' in json_query:
Hey Ronie!  I believe you helped me with an add-on, or Kodi code issue in the past. 

Many thanks, I'll test that now!

Cheers,
Ken
Reply
#4
(2021-05-13, 10:49)ronie Wrote: you should indeed remove that line, it isn't needed anymore in py3.

as for the error, 'has_key()' has been removed in python 3,
you can replace it with if 'result' in json_query:

It works!  You are a legend, thanks Ronie!
Reply

Logout Mark Read Team Forum Stats Members Help
Assistance converting Python 2 to 3 in an addon0