Skip to content

Commit

Permalink
Added gzip response data decoding
Browse files Browse the repository at this point in the history
TypeError: Parse() argument 1 must be string or read-only buffer, not None
  • Loading branch information
zbyna committed May 25, 2019
1 parent 85ea2d6 commit 88ae721
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ivysilani.py
Expand Up @@ -179,6 +179,7 @@ def url(self, quality):
"quality": quality.quality()}
data = None
try:
xbmc.log('" PLAYLISTURL_URL je: "' + PLAYLISTURL_URL)
data = _fetch(PLAYLISTURL_URL, params)
xbmc.log('"Data z PLAYLISTURL_URL jsou: "' + str(data))
except:
Expand Down Expand Up @@ -314,11 +315,24 @@ def _https_ceska_televize_fetch(url, params):
"Accept-encoding": "gzip",
"Connection": "Keep-Alive",
"User-Agent": "Dalvik/1.6.0 (Linux; U; Android 4.4.4; Nexus 7 Build/KTU84P)"}
xbmc.log('"_https_ceska_televize_fetch ... begin"')
conn = httplib.HTTPSConnection("www.ceskatelevize.cz")
conn.request("POST", url, urllib.urlencode(params), headers)
xbmc.log('" url je: "' + str(url))
xbmc.log('" params jsou: "' + str(params))
response = conn.getresponse()
xbmc.log('"response headers jsou: "' + str(response.getheaders()))
xbmc.log('"response status je: "' + str(response.status))
if response.status == 200:
data = response.read()
if response.getheader('content-encoding', 'default') == 'gzip':
try:
from cStringIO import StringIO
from gzip import GzipFile
data2 = GzipFile('', 'r', 0, StringIO(data)).read()
data = data2
except:
xbmc.log('"Decompress error "')
conn.close()
return data
return None
Expand All @@ -335,19 +349,22 @@ def _token_refresh():


def _fetch(url, params):
xbmc.log('"_fetch ... begin"')
if _token is None:
_token_refresh()
params["token"] = _token
xbmc.log('"Token je: "' + str(_token))
data = _https_ceska_televize_fetch(url, params)
try:
xbmc.log('" Data jsou: "' + str(data))
root = ET.fromstring(data)
except:
return None
if root.tag == "errors":
if root[0].text == "no token sent" or root[0].text == "wrong token":
_token_refresh()
data = _https_ceska_televize_fetch(url, params)
xbmc.log('"Data jsou: "' + str(data))
xbmc.log('"Data errors jsou: "' + str(data))
else:
raise Exception(', '.join([e.text for e in root]))
return data
Expand Down

0 comments on commit 88ae721

Please sign in to comment.