favetelinguis

favetelinguis

Httpoison with client certification throws error that gives no info

Im trying to implement the folowing call in Elixir:

curl -q -k --cert client-2048.crt --key client-2048.key
https://identitysso.betfair.com/api/certlogin -d
"username=testuser&password=testpassword" -H "X-Application:
curlCommandLineTest"

This is what I have so far:

defmodule BfgEngine.Client.Betfair do
alias BfgEngine.API.Betfair.{Login}
def login(%{username: username, password: password, certs: certs}) do
body = %{username: username, password: password}
Login.post("/certlogin", body)
|> IO.inspect()
end
end

defmodule BfgEngine.API.Betfair.Login do
use HTTPoison.Base

@base_url " https://identitysso.betfair.com/api"

@expected_fields ~w(sessionToken loginStatus)

def process_url(resource) do
@base_url <> resource
end

def process_request_headers(_headers) do
[
“X-Application”: “1”,
“content-type”: “application/x-www-form-urlencoded”,
“Accept”: “Application/json; Charset=utf-8”
]
end

def process_response_body(body) do
body
|> Poison.decode!()
|> Map.take(@expected_fields)
|> Enum.map(fn {k, v} -> {String.to_atom(k), v} end)
end

def process_request_body(%{username: username, password: password}) do
“username=#{username}&password=#{password}”
|> URI.encode_www_form()
end

def process_request_options(_options) do
[
ssl: [
certfile: “/certs/client-2048.pem”,
keyfile: “/certs/client-2048.key”
]
]
end
end

However in the repl im getting the following error:

Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> BfgEngine.API.Betfair.Login.start
{:ok, []}
iex(2)> BfgEngine.Client.Betfair.login(%{password: “///////”, username: “/////”, app_key: “//////”, certs: “”})
** (exit) :badarg
(kernel) gen_tcp.erl:153: :gen_tcp.connect/4
(hackney) /Users/henriklarsson/repos/elixir/bfg_engine/deps/hackney/src/hackney_connect.erl:247: :hackney_connect.do_connect/5
(hackney) /Users/henriklarsson/repos/elixir/bfg_engine/deps/hackney/src/hackney_connect.erl:37: :hackney_connect.connect/5
(hackney) /Users/henriklarsson/repos/elixir/bfg_engine/deps/hackney/src/hackney.erl:316: :hackney.request/5
(httpoison) lib/httpoison/base.ex:630: HTTPoison.Base.request/9
(bfg_engine) lib/bfg_engine/betfair.ex:27: BfgEngine.Client.Betfair.login/1

Now my questions are:

  1. What causes this error.
  2. Is this a good way of implementing a rest client?
  3. Are there any other problems with this implementation to get it working in the same way as the curl?

Marked As Solved

OvermindDL1

OvermindDL1

This means a bad argument was given to the socket, so a bad URL most likely.

A space at the front of the url is not valid, so this is most likely the cause. :slight_smile:

Also Liked

NobbZ

NobbZ

You should keep the post, such that it helps in the future with similar problems. I’d be happy if you could revert your changes and format your original text that it gets displayed properly.

OvermindDL1

OvermindDL1

If my post fixed it you should mark it as the solution, you’d be surprised at how often something like URL formatting can trip up people. :slight_smile:

EDIT: Awesome thanks, now it is more easily searchable! :smiley:

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement