Misc

How to fix YouTube login in XBMC

By Max
February 14, 2014
0

I switched from MediaPortal to XBMC a year ago when i went after a dedicated HTPC. The transition was pretty simple, just installed OpenElec on the SSD and with a few configurations everything was in place.
Well .. Almost 🙂 I have installed the Youtube xbmc plugin , but could not login. I worked around the problem for a while, using Yatse to send videos to the XBMC.

But sometimes you want just to sit on your couch with only the remote and browse some videos.  So i began searching for a solution.
You can find the log in the “/storage/.xbmc/temp” folder.

I found something like that:

18:25:04 T:140506222814976   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error
 Error Contents: 'ascii' codec can't encode character u'\u021b' in position 7: ordinal not in range(128)
 Traceback (most recent call last):
 File "/storage/.xbmc/addons/plugin.video.youtube/default.py", line 111, in
   login.login()
 File "/storage/.xbmc/addons/plugin.video.youtube/YouTubeLogin.py", line 75, in login
   result, status = self.authorize()
 File "/storage/.xbmc/addons/plugin.video.youtube/YouTubeLogin.py", line 85, in authorize
   (result, status) = self._httpLogin({"new": "true"})
 File "/storage/.xbmc/addons/plugin.video.youtube/YouTubeLogin.py", line 183, in _httpLogin
   ret = self.core._fetchPage(fetch_options)
 File "/storage/.xbmc/addons/plugin.video.youtube/YouTubeCore.py", line 400, in _fetchPage
   request = urllib2.Request(link, urllib.urlencode(get("url_data")))
 File "./Lib/urllib.py", line 1312, in urlencode
 UnicodeEncodeError: 'ascii' codec can't encode character u'\u021b' in position 7: ordinal not in range(128)
 -->End of Python script error report

As you can see the error seemed to be about a encoding issue in the YouTubeCore.py, at line 400.
Tt looked like this:


        if get("url_data"):
            request = urllib2.Request(link, urllib.urlencode(get("url_data")))
            request.add_header('Content-Type', 'application/x-www-form-urlencoded'

The solution was to encode all the values in the url_data map to UTF-8 😉


        if get("url_data"):
            change_get = get("url_data")
            for k, v in change_get.iteritems():
                change_get[k] = unicode(v).encode('utf-8')
            request = urllib2.Request(link, urllib.urlencode(change_get))
            request.add_header('Content-Type', 'application/x-www-form-urlencoded'

Take care at the indentation, python is really pretentious about that 🙂

Comments: 0

Leave a Reply

Your email address will not be published. Required fields are marked *