Search code examples
javahttphttpclienthttp-status-code-308algorithmia

com.algorithmia.APIException: 308 unexpected API response


I'm using algorithmia, a repository of trained ML functions on the Internet. Few weeks ago, an issue showed up, and since then, haven't been able to figure out what's going on. I'm executing this code, which can be found on their official site.

import com.algorithmia.Algorithmia;
import com.algorithmia.AlgorithmiaClient;
import com.algorithmia.algo.AlgoResponse;
import com.algorithmia.algo.Algorithm;

public class Main {

    public static void main(String[] args) throws Exception {
        String input = "A purely peer-to-peer...";
        AlgorithmiaClient client = Algorithmia.client("api_key");
        Algorithm algo = client.algo("nlp/Summarizer/0.1.8");
        algo.setTimeout(300L, java.util.concurrent.TimeUnit.SECONDS); //optional
        AlgoResponse result = algo.pipe(input);
        System.out.println(result.asJsonString());
    }

}

But this code raises the following exception:

Exception in thread "main" com.algorithmia.APIException: 308 unexpected API response: 
    at com.algorithmia.algo.Algorithm.pipeRequest(Algorithm.java:145)
    at com.algorithmia.algo.Algorithm.pipe(Algorithm.java:96)
    at Main.main(Main.java:13)

I want to help out

  1. Create a maven project
  2. Add this maven dependency
<dependency>
  <groupId>com.algorithmia</groupId>
  <artifactId>algorithmia-client</artifactId>
  <version>[,1.1.0)</version>
</dependency>
  1. Paste the code showed above

Further observations and guessings

  • Issuing a cURL request everything works as expected
  • Using Python works fine
  • It may have something to do with HttpClient
  • The Java code will work with a proxy like Charles
  • Refer to the opened issue on GitHub

Solution

  • Given the current date, 2nd July 2019, they published version 1.0.16 that fix such error.