XLordKX / kodi

kodi plugins & addons
211 stars 80 forks source link

German umlaut in password causes script to crash while login #25

Open crea-doo opened 8 years ago

crea-doo commented 8 years ago

When trying to login with credentials where a umlaut is contained in the password the scripts fails with the following error:

23:09:26 T:1599075360  NOTICE: -->Python Interpreter Initialized<--
23:10:25 T:1599075360   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.UnicodeEncodeError'>
                                            Error Contents: 'ascii' codec can't encode character u'\xe4' in position 7: ordinal not in range(128)
                                            Traceback (most recent call last):
                                              File "/home/osmc/.kodi/addons/plugin.video.prime_instant/default.py", line 1405, in <module>
                                                login()
                                              File "/home/osmc/.kodi/addons/plugin.video.prime_instant/default.py", line 1097, in login
                                                content = br.submit().read()
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_mechanize.py", line 541, in submit
                                                return self.open(self.click(*args, **kwds))
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_mechanize.py", line 530, in click
                                                request = self.form.click(*args, **kwds)
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_form.py", line 2999, in click
                                                self._request_class)
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_form.py", line 3201, in _click
                                                return control._click(self, coord, return_type, request_class)
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_form.py", line 2350, in _click
                                                r = form._switch_click(return_type, request_class)
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_form.py", line 3269, in _switch_click
                                                req_data = self._request_data()
                                              File "/home/osmc/.kodi/addons/script.module.mechanize/lib/mechanize/_form.py", line 3243, in _request_data
                                                return (uri, urllib.urlencode(self._pairs()),
                                              File "/usr/lib/python2.7/urllib.py", line 1338, in urlencode
                                                v = quote_plus(str(v))
                                            UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 7: ordinal not in range(128)
                                            -->End of Python script error report<--
23:10:25 T:1957085184   ERROR: GetDirectory - Error getting plugin://plugin.video.prime_instant/?mode=browseMovies&thumb&url&videoType
23:10:25 T:1957085184   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.prime_instant/?mode=browseMovies&thumb&url&videoType) failed

Seems to be an encoding issue...

metaflux commented 8 years ago

Same issue here:

EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

metaflux commented 8 years ago

The problem is, that you want to cast a unicode-string to a string, but there are some characters that have to be converted to ASCII first.

"quote_plus(str(v))" to "quote_plus(str(v.encode("utf-8")))"
or "urllib.urlencode(unicode(v).encode('utf-8'))" I do not know what you are using...

(v is a unicode-string) Or you could switch to Python 3.x, where all strings are unicode by default.