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:
- What causes this error.
- Is this a good way of implementing a rest client?
- Are there any other problems with this implementation to get it working in the same way as the curl?
Marked As Solved
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. ![]()
1
Also Liked
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.
2
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. 
EDIT: Awesome thanks, now it is more easily searchable! 
1
Popular in Questions
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
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
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
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
I would like to know what is the best IDE for elixir development?
New
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
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
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
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
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
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
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
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
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
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
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
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
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New







