HTTPoison request: "1st argument: the table identifier does not refer to an existing ETS table" when calling function outside module

I am trying to use HTTPoison to get some data from an API, but I’m getting an error which I’m not able to resolve. My project currently looks like this:

defmodule EnergyZeroViewer do
  def execute do
    data = get_data()
    table = create_table(data)


  defp get_data do
    # ?fromDate=2023-01-25T23%3A00%3A00.000Z
    # &tillDate=2023-01-26T22%3A59%3A59.999Z
    # &interval=4
    # &usageType=1
    # &inclBtw=true

    fromDate =!(Date.utc_today(), ~T[00:00:00], "Etc/UTC") |> DateTime.to_iso8601()
    tillDate =!(Date.utc_today(), ~T[23:59:59], "Etc/UTC") |> DateTime.to_iso8601()

    default_parameters = %{
      fromDate: fromDate,
      tillDate: tillDate,
      interval: 4,
      usageType: 1,
      inclBtw: true

    energy_url = ""
    result = HTTPoison.get!(energy_url, [], params: default_parameters)

  defp create_table(energy_data) do
    {:ok, fromDate, _} = Map.get(energy_data, "fromDate") |> DateTime.from_iso8601()
    title = "#{Calendar.strftime(fromDate, "%d %B %Y")}"
    header = ["price", "time"]
    data = Map.get(energy_data, "Prices")

    rows =, fn data_point ->
        price = Map.get(data_point, "price")
        {:ok, time, _} = Map.get(data_point, "readingDate") |> DateTime.from_iso8601()

          price |> Float.round(2)

    TableRex.quick_render!(rows, header, title)


The EnergyZeroViewer.execute() call outside the module is giving me the following error:

== Compilation error in file lib/energy_zero_viewer.ex ==
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: the table identifier does not refer to an existing ETS table

    (stdlib 4.2) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
    (hackney 1.18.1) /home/sylvester/Code/ElixirProjects/energy_zero_viewer/deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
    (hackney 1.18.1) /home/sylvester/Code/ElixirProjects/energy_zero_viewer/deps/hackney/src/hackney_connect.erl:75: :hackney_connect.create_connection/5
    (hackney 1.18.1) /home/sylvester/Code/ElixirProjects/energy_zero_viewer/deps/hackney/src/hackney_connect.erl:44: :hackney_connect.connect/5
    (hackney 1.18.1) /home/sylvester/Code/ElixirProjects/energy_zero_viewer/deps/hackney/src/hackney.erl:335: :hackney.request/5
    (httpoison 1.8.2) lib/httpoison/base.ex:846: HTTPoison.Base.request/6
    (httpoison 1.8.2) lib/httpoison.ex:258: HTTPoison.request!/5
    lib/energy_zero_viewer.ex:29: EnergyZeroViewer.get_data/0

However, when I run this function manually in IEX it works without any errors. What am I doing wrong here?

Where are you calling this? Basically this means that httpoison isn’t started, which means your application isn’t yet started. You can start it manually via Application.ensure_all_started(:httpoison) but normally it should already be booted.

1 Like

It’s a mix application, so I’m using mix run, however using iex -S mix also gives me this error. The code I sent is everything inside lib/energy_zero_viewer.ex

It works after adding Application.ensure_all_started(:httpoison) above the function call. Thanks!

Edit: nevermind my understanding of mix applications was completely incorrect. I thought that mix run was the way to start my application, but after some more searching I need to make edits to my mix.exs file

1 Like

Can you show your mix.exs file?

Iirc that error happens when :hackney is not started. Why it’s not started I can’t say though.

At the time it looked like this, the default: mix.exs · 630be871f92e4966934edf61add5a1db0ac5ddcb · Sylvester Roos / EnergyZero viewer · GitLab

Now it looks like this: mix.exs · 0ecb1027fbf42c5be719de5af6493c5071c5dac3 · Sylvester Roos / EnergyZero viewer · GitLab

I create the binary with mix and am able to run this binary without any issue