0

I am using the Kodi API, to control my htpc via asp.net. Especialy the functio named "Playlist.Add". The Json I send is like this:

{"jsonrpc":"2.0","method":"Playlist.Insert","params":{"playlistid":0,"position":0,"item":{"file":"smb://server/Ferry Corsten/Beautiful/Ferry Corsten - Beautiful (Extended).mp3"}},"id":1}

This is working fine. But when there are some none english characters in the string like this:

{"jsonrpc":"2.0","method":"Playlist.Insert","params":{"playlistid":0,"position":0,"item":{"file":"smb://server/01-Zum Geburtstag viel Glück.mp3"}},"id":1}

It is just throwing a "RequestCanceled" Exception.

My c# source is like this:

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_url);
                string authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(_username + ":" + _password));
                webRequest.Headers["Authorization"] = "Basic " + authInfo;

                webRequest.Method = "POST";
                webRequest.UserAgent = "KodiControl";
                webRequest.ContentType = "application/json";

                webRequest.ContentLength = json.Length;
                using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
                {
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

The Exception is thrown at streamWriter.Flush(). So what do I have to do to send this request?``

Chris
  • 1,610
  • 3
  • 18
  • 37

1 Answers1

0

I suggest you look into Kodi addon unicode paths Following that guide will help you prevent common problems with non-latin characters in Kodi.

Python only works with unicode strings internally, converting to a particular encoding on output. (or input)". To make string literals unicode by default, add

from __future__ import unicode_literals

Addon path

path = addon.getAddonInfo('path').decode('utf-8')

.decode('utf-8') tells kodi to decode the given function using utf-8. Kodi's getAddonInfo returns an UTF-8 encoded string and we decode it an unicode.

Browse dialog

dialog = xbmcgui.Dialog()
directory = dialog.browse(0, 'Title' , 'pictures').decode('utf-8')

dialog.browse() returns an UTF-8 encoded string which perhaps contains some non latin characters. Therefore decode it to unicode!

evilpanda
  • 26
  • 6
  • Rather than just link to a guide, perhaps you can give some specific info in this post in case that links breaks and future users need help. – Fencer04 Nov 15 '16 at 21:18