Hello,
I am trying to send a request to a server on the same network.
def unload_model(conn, %{"id" => id}) do
case Frontend.Repo.get(LoadedModel, id) do
nil ->
{:error, "LoadedModel with id #{id} not found"}
loaded_model ->
# Construct the URL and payload for the DELETE request
url = "http://10.0.20.78:8000/admin/unoad_model"
payload = %{model_id: id}
headers = [
{"Content-Type", "application/json"},
{'api_key', conn.assigns.current_user.api_key}
]
# Send the DELETE request to the server
case send_delete_request(url, payload, headers) do
{:ok, _response} ->
{:ok, "Model unloaded successfully"}
{:error, reason} ->
{:error, "Failed to unload model: #{reason}"}
end
end
end
defp send_delete_request(url, payload, headers) do
case HTTPoison.delete(url, body: Jason.encode!(payload), headers: headers) do
{:ok, response} ->
{:ok, response}
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, "HTTPoison error: #{inspect(reason)}"}
end
end
Earlier i got errors regarding SSL certificate:
{:tls_alert, {:unknown_ca, 'TLS client: In state wait_cert_cr at ssl_handshake.erl:2111 generated CLIENT ALERT: Fatal - Unknown CA\n'}}
After that, i started getting a new error:
errors were found at the given arguments:
* 1st argument: not an iodata term
I think this is whats causing the error
:erlang.list_to_binary([{"Content-Type", "application/json"}, {"api_key", "...."}])
i assume the error is related to the body of the request being unrealizable or something like that, i’ve tried many things, but i don’t know what else to do.
Thanks