Kodi Community Forum
Pandora Json Help - 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: Pandora Json Help (/showthread.php?tid=132957)



Pandora Json Help - newatv2user - 2012-06-01

So I've been playing with the Json api to get the pandora addon to work. But I've hit a problem I can't seem to understand.
First, here's the part of debug log:
Code:
NOTICE: JsonGetURL:
16:34:34 T:5928 NOTICE: Url: http://tuner.pandora.com/services/json/?method=user.getStationList&auth_token=VI%2F6qydeGak8ipm%2Bvr4F%2BZogv27V%2Fd2a649kIEOde8atw%3D&partner_id=42&user_id=REDACTED
16:34:34 T:5928 NOTICE: postData: 0b5b3f806abef32879a802a0749e65e921273e594f5d63b3baca343ea9357bc32fcf397efe26cecbaadc92a2cf3da058404d0a13a1878461a9de5d00512b44dc491108c6b8cfdf2f0fd570086c48a42028891021591af88d5f58b7bd7541aaea
16:34:34 T:5928 NOTICE: After Request
16:34:34 T:5928 NOTICE: Error at JsonGetURL: WTF?
16:34:34 T:5928 ERROR: Exception in python script callback execution
16:34:34 T:5928 ERROR: Traceback (most recent call last):
16:34:34 T:5928 ERROR: File "C:\Documents and Settings\XXXXX\Application Data\XBMC\addons\script.xbmc.pandorajson\pandagui.py", line 39, in onInit
16:34:34 T:5928 ERROR: self.getControl(BTN_THUMBED_DN).setVisible(False)
16:34:34 T:5928 ERROR: TypeError
16:34:34 T:5928 ERROR: :
16:34:34 T:5928 ERROR: Non-Existent Control 337

Here is the JsonGetURL method:
Code:
def JsonGetURL(Url, postData=None):
    print 'JsonGetURL:'
    print 'Url: ' + Url
    print 'postData: ' + postData
    try:
        req = urllib2.Request(Url, postData, {'Content-Type': 'application/json'})
        print 'After Request'
        u = urllib2.urlopen(req)
        print 'After urlopen:'
        resp = u.read()
        u.close()
        return resp
        print 'After return?'
    except:
        print 'Error at JsonGetURL: WTF?'
        return None

The confusing part for me is, if I call the method directly (manually) using the postdata and url, it works. But when it is called from pandagui, it results in the error posted above. If anyone can explain to me what is happening, what I'm doing wrong, that would really help. Thanks.


RE: Pandora Json Help - divingmule - 2012-06-03

It looks like your getting an error with -
Code:
u = urllib2.urlopen(req)

It is being ignored because of the try/except and the function is returning None. Remove the try/except to see what the real error is.

Code:
def JsonGetURL(Url, postData=None):
    print 'JsonGetURL:'
    print 'Url: ' + Url
    print 'postData: ' + postData
    # try:
    req = urllib2.Request(Url, postData, {'Content-Type': 'application/json'})
    print 'After Request'
    u = urllib2.urlopen(req)
    print 'After urlopen:'
    resp = u.read()
    u.close()
    return resp
        #print 'After return?'
    # except:
        # print 'Error at JsonGetURL: WTF?'
        # return None



RE: Pandora Json Help - newatv2user - 2012-06-03

Didn't thought about that. Will try. Thanks.


RE: Pandora Json Help - newatv2user - 2012-06-03

Ok here is the error log now:
Code:
15:36:42 T:2052 ERROR: Exception in python script callback execution
15:36:42 T:2052 ERROR: Traceback (most recent call last):
15:36:42 T:2052 ERROR: File "C:\Users\Vaio\AppData\Roaming\XBMC\addons\script.xbmc.pandorajson\pandagui.py", line 34, in onInit
15:36:42 T:2052 ERROR: for s in self.panda.getStations():
15:36:42 T:2052 ERROR: File "C:\Users\Vaio\AppData\Roaming\XBMC\addons\script.xbmc.pandorajson\default.py", line 131, in getStations
15:36:42 T:2052 ERROR: return self.pandora.GetStationList()
15:36:42 T:2052 ERROR: File "C:\Users\Vaio\AppData\Roaming\XBMC\addons\script.xbmc.pandorajson\libpandora\pandora.py", line 98, in GetStationList
15:36:42 T:2052 ERROR: responseData = JsonGetURL(Url, encPostData)
15:36:42 T:2052 ERROR: File "C:\Users\Vaio\AppData\Roaming\XBMC\addons\script.xbmc.pandorajson\libpandora\utils.py", line 14, in JsonGetURL
15:36:42 T:2052 ERROR: try: u = urllib2.urlopen(req)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 126, in urlopen
15:36:42 T:2052 ERROR: return _opener.open(url, data, timeout)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 391, in open
15:36:42 T:2052 ERROR: response = self._open(req, data)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 409, in _open
15:36:42 T:2052 ERROR: '_open', req)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 369, in _call_chain
15:36:42 T:2052 ERROR: result = func(*args)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 1170, in http_open
15:36:42 T:2052 ERROR: return self.do_open(httplib.HTTPConnection, req)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 1116, in do_open
15:36:42 T:2052 ERROR: h = http_class(host, timeout=req.timeout) # will parse host:port
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\httplib.py", line 661, in __init__
15:36:42 T:2052 ERROR: self._set_hostport(host, port)
15:36:42 T:2052 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\httplib.py", line 686, in _set_hostport
15:36:42 T:2052 ERROR: raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
15:36:42 T:2052 ERROR: httplib
15:36:42 T:2052 ERROR: .
15:36:42 T:2052 ERROR: InvalidURL
15:36:42 T:2052 ERROR: :
15:36:42 T:2052 ERROR: nonnumeric port: ''

Still, if I call it manually from a test module, it works. Still does not make sense to me!


RE: Pandora Json Help - newatv2user - 2012-06-03

Never mind guys. VTWoods already has a working solution. So I'm using my time somewhere else. Smile