henriquesati

henriquesati

** (ArgumentError) unknown registry: Req.Finch on a simple http request using Req library

I’m doing a POST request using Req but i’m getting the error ** (ArgumentError) unknown registry: Req.Finch. I found the same problem on elixir reddit but I couldnt manage to understand and apply the possible solution
My code:

defmodule GetPayloadInfo do

  def doReq do
    token = "XXX"
    req = Req.Request.new(method: :post, url: "https://sandbox.asaas.com/api/v3/pix/qrCodes/decode")
    req = Req.Request.put_headers(req, [{"accept", "application/json"}, {"acess_token", token}, {"content-type", "application/json"} ])

    {req, resp} = Req.Request.run_request(req)
  end

end

Then I simply call the function on my main file with a simple hello world output so make sure its all fine before this

Hello.say_hi()
GetPayloadInfo.doReq()

and this is my mix.exs file

defmodule TestesPay.MixProject do
  use Mix.Project

  def project do
    [
      app: :testes_pay,
      version: "0.1.0",
      elixir: "~> 1.16",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      telemetry: [enabled: false],
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:req, "~> 0.5.0"}
      # {:dep_from_hexpm, "~> 0.3.0"},
      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
    ]
  end
end
the code contains no scripts, only .ex files, located at lib

Most Liked

LorenzoD

LorenzoD

For those finding this thread after running into this error when using Req in a function within a Mix.Task module: This problem is resolved by adding @requirements ["app.start"] at the module level. This ensures that Req and its dependencies are available for use when you execute the Mix task.

More information can be found in the documentation here.

wojtekmach

wojtekmach

Hex Core Team
== Compilation error in file lib/cry.ex ==

Oh, you’re using Req at compile-time, i.e. in module body and similar. In that case it seems you need to explicitly start dependencies:

defmodule Foo do
  {:ok, _} = Application.ensure_all_started(:req)
  Req.get(...)
end
wojtekmach

wojtekmach

Hex Core Team

compile-time vs runtime is a pretty broad topic so to just scratch the surface when you have a module:

def Foo do
  IO.puts :at_compile_time

  def foo do
    IO.puts :at_runtime
  end
end

the first IO.puts is executed while the module is being compiled. When it is being used at runtime, that IO.puts will not be executed. On the other hand, the second IO.puts is NOT executed when the module is being compiled. It is only executed when you call Foo.foo(). Doing things at compile-time is definitely an Elixir super power and for this particular use case you need that Application.ensure_all_started. (The reason is Req library starts a supervision tree in its application callback module. If it didn’t, ensure_all_started would not be necessary.) In vast majority of day to day Elixir programming, you don’t need ensure_all_started, it is done for you.

dimitarvp

dimitarvp

No, not at all. Modules are loaded just fine but there is the concept of applications that start various OTP processes which is achieved by the applications themselves being “started” (“application” being a useful abstraction here).

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
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
Tee
can someone please explain to me how Enum.reduce works with maps
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

Other popular topics 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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement