2013-10-23, 21:54
The ondertitels.com subtitle provider is broken and will not download subtitles. The error logged in xbmc.log is:
19:59:59 T:140093527381760 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type:
Error Contents: 'NoneType' object is not iterable
Traceback (most recent call last):
File "/storage/.xbmc/addons/script.xbmc.subtitles/resources/lib/gui.py", line 492, in onClick
self.Download_Subtitles( self.getControl( SUBTITLES_LIST ).getSelectedPosition())
File "/storage/.xbmc/addons/script.xbmc.subtitles/resources/lib/gui.py", line 301, in Download_Subtitles
self.session_id
TypeError: 'NoneType' object is not iterable
-->End of Python script error report<--
The entire xbmc.log is available at pastebin:
http://sprunge.us/cUXW
I am doing some investigation myself and found out the problem is the regular expression that is scraping the download url from the ondertitels.com webpage.
When changing the downloadlink_pattern to "<a href=\"/(getdownload\.php\?id=\d{1,10}&userfile=[^\n\r\t]*\.\w{3})\"><b>Download</b></a>" the download link is fetched successfully but I am encountering an error when trying to save the zip file to the temp location.
The error thrown is: "ascii' codec can't decode byte 0xd7 in position 18: ordinal not in range(128)"
Full log at: http://sprunge.us/NSNj
The geturl method executes a request.get(url, cookie) and returns r.content
When writing the content returned from the above method to disk the encoding error is thrown. (see local_file_handle.write(content) below)
I do not have that much knowledge in the python language and am struggling to fix this encoding issue. The content variable is of type str.
The strange thing is, in my "test project" on my Windows environment the file is written to disk without a problem. When doing the same on linux the encoding error is thrown. (OpenElec 3.2.3)
Can somebody help me fix this encoding issue so I can fix the ondertitels.com provider?
19:59:59 T:140093527381760 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type:
Error Contents: 'NoneType' object is not iterable
Traceback (most recent call last):
File "/storage/.xbmc/addons/script.xbmc.subtitles/resources/lib/gui.py", line 492, in onClick
self.Download_Subtitles( self.getControl( SUBTITLES_LIST ).getSelectedPosition())
File "/storage/.xbmc/addons/script.xbmc.subtitles/resources/lib/gui.py", line 301, in Download_Subtitles
self.session_id
TypeError: 'NoneType' object is not iterable
-->End of Python script error report<--
The entire xbmc.log is available at pastebin:
http://sprunge.us/cUXW
I am doing some investigation myself and found out the problem is the regular expression that is scraping the download url from the ondertitels.com webpage.
When changing the downloadlink_pattern to "<a href=\"/(getdownload\.php\?id=\d{1,10}&userfile=[^\n\r\t]*\.\w{3})\"><b>Download</b></a>" the download link is fetched successfully but I am encountering an error when trying to save the zip file to the temp location.
The error thrown is: "ascii' codec can't decode byte 0xd7 in position 18: ordinal not in range(128)"
Full log at: http://sprunge.us/NSNj
The geturl method executes a request.get(url, cookie) and returns r.content
PHP Code:
def geturl(url, action=FETCH_NORMAL, cookiedata=''):
log( __name__ ,"%s Getting url:%s" % (debug_pretext, url))
try:
if action == FETCH_SUBTITLE:
r = requests.get(url, cookies=cookiedata)
return r.content
elif action == FETCH_COOKIE:
r = requests.get(url)
return (r.text, r)
else:
r = requests.get(url)
return r.text
except:
log( __name__ ,"%s Failed to get url:%s" % (debug_pretext, url))
return None
When writing the content returned from the above method to disk the encoding error is thrown. (see local_file_handle.write(content) below)
PHP Code:
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input
log( __name__ ,"subtitles_list: %s: " % (subtitles_list))
log( __name__ ,"pos %s: " % (pos))
log( __name__ ,"zip_subs %s: " % (zip_subs))
log( __name__ ,"tmp_sub_dir %s: " % (tmp_sub_dir))
log( __name__ ,"sub_folder %s " % (sub_folder))
log( __name__ ,"session_id %s " % (session_id))
url = main_url + subtitles_list[pos][ "link" ]
local_tmp_file = zip_subs
content, cookie = geturl(url, FETCH_COOKIE)
downloadlink = getdownloadlink(content)
log( __name__ ,"downloadlink %s: " % (downloadlink))
if downloadlink is not None:
try:
url = main_url + downloadlink
log( __name__ ,"url %s: " % (url))
url = string.replace(url," ","+")
log( __name__ ,"url %s: " % (url))
log( __name__ ,"%s Fetching subtitles using url %s - and cookie: %s" % (debug_pretext, url, cookie.cookies))
content = geturl(url, FETCH_SUBTITLE, cookie.cookies)
log( __name__ ,"content %s: " % (content))
if content is not None:
log( __name__ ,"%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
local_file_handle = open(local_tmp_file, "w" + "b")
local_file_handle.write(content)
local_file_handle.close()
except:
log( __name__ ,"%s Failed to save subtitles to '%s'" % (debug_pretext, local_tmp_file))
log( __name__ ,"%s Subtitles saved to '%s'" % (debug_pretext, local_tmp_file))
language = subtitles_list[pos][ "language_name" ]
return True, language, "" #standard output
I do not have that much knowledge in the python language and am struggling to fix this encoding issue. The content variable is of type str.
The strange thing is, in my "test project" on my Windows environment the file is written to disk without a problem. When doing the same on linux the encoding error is thrown. (OpenElec 3.2.3)
Can somebody help me fix this encoding issue so I can fix the ondertitels.com provider?