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

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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

We're in Beta

About us Mission Statement