I got the error mentioned in the title while running the following code. The weird part is I did get the response I expected but with this message attached.
defmodule Kodi.Worker do
def get_response() do
result = url_for() |> HTTPoison.get |> parse_response
case result do
{:ok, response} -> "response: #{response}"
:error -> "query error"
end
end
defp url_for() do
"http://192.168.0.104:8080/jsonrpc?request={%22jsonrpc%22:%20%222.0%22,%20%22id%22:%201,%20%22method%22:%20%22Playlist.GetPlaylists%22}"
end
defp parse_response({:ok, %HTTPoison.Response{body: body, status_code: 200}}) do
body |> JSON.decode! |> filter_response
end
defp parse_response(_) do
:error
end
defp filter_response(json) do
try do
#response = (json["result"])
#{:ok, response}
{:ok, json}
rescue
_ -> :error
end
end
end
Any idea?
EDIT:
Error message:
** (Protocol.UndefinedError) protocol String.Chars not implemented for %HTTPoison.Response{body: “{"id":1,"jsonrpc":"2.0","result":[{"playlistid":0,"type":"audio"},{"playlistid":1,"type":"video"},{"playlistid":2,"type":"picture"}]}”, headers: [{“Content-Length”, “133”}, {“Content-Type”, “application/json”}, {“Date”, “Wed, 04 May 2016 05:00:55 GMT”}], status_code: 200}
(elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir) lib/string/chars.ex:17: String.Chars.to_string/1
(kodi) lib/worker.ex:5: Kodi.Worker.get_response/0
It looks like you are correct. I might be treating the response as string when it’s not. I will look into it again to figure out how to fix it. Thanks.
I made a mistake in my code. I am fixing it and update the thread “soon”.






















