algorithmia-java icon indicating copy to clipboard operation
algorithmia-java copied to clipboard

Algorithmia.client() call fails

Open alfredsteele opened this issue 6 years ago • 7 comments

I have been unable to connect to Algorithmia after many different attempts. I even created a new key with full access. The call below throws the exception below.

final AlgorithmiaClient client = Algorithmia.client("MY_KEY");

Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:666) at com.algorithmia.client.HttpClient.(HttpClient.java:79) at com.algorithmia.AlgorithmiaClient.(AlgorithmiaClient.java:19) at com.algorithmia.Algorithmia.client(Algorithmia.java:49) at com.steele.algorithmia.DataAPI.main(DataAPI.java:19)

alfredsteele avatar Sep 04 '17 07:09 alfredsteele

My current hypothesis is that you have a system setting that isn't playing nicely with the apache http client that we use. The line that I think to blame is this: https://github.com/algorithmiaio/algorithmia-java/blob/master/src/main/java/com/algorithmia/client/HttpClient.java#L78 Do you know what the https.protocols and https.cipherSuites values are for your system properties?

If you are running this from our source, can you try commenting out that line? This is also a new change, so if you go back to version 1.0.12, that should fix it too.

jamesatha avatar Sep 04 '17 22:09 jamesatha

No luck. I tried source versions v1.0.12 and v1.0.10. I still get the same error. The two properties https.protocols and https.cipherSuites are not defined. What values should they be set to?

On Mon, Sep 4, 2017 at 5:54 PM, James Athappilly [email protected] wrote:

My current hypothesis is that you have a system setting that isn't playing nicely with the apache http client that we use. The line that I think to blame is this: https://github.com/algorithmiaio/algorithmia- java/blob/master/src/main/java/com/algorithmia/client/HttpClient.java#L78 Do you know what the https.protocols and https.cipherSuites values are for your system properties?

If you are running this from our source, can you try commenting out that line? This is also a new change, so if you go back to version 1.0.12, that should fix it too.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/algorithmiaio/algorithmia-java/issues/12#issuecomment-327036458, or mute the thread https://github.com/notifications/unsubscribe-auth/AeJeiclgo4bBlYCrRQsTD5aWlaowfqP3ks5sfH-pgaJpZM4PLi2R .

alfredsteele avatar Sep 04 '17 23:09 alfredsteele

I've looked at the apache http client code and it should work if the two are unset. Was the error exactly the same in each case?

jamesatha avatar Sep 05 '17 00:09 jamesatha

My test program is below with the stack traces from three versions of the Java API. I attached an image of my lib directory so you can see which jar versions I am using. At the bottom is a demo program from the web site. I only changed the package and class names. It throws the same exception on line 19 for all versions of the API.

==============================================================================

package com.steele.algorithmia;

import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files;

import com.algorithmia.APIException; import com.algorithmia.AlgorithmException; import com.algorithmia.Algorithmia; import com.algorithmia.AlgorithmiaClient; import com.algorithmia.TypeToken; import com.algorithmia.algo.AlgoResponse; import com.algorithmia.algo.Algorithm;

/**


  • The Class ColorfulImageColorization. / public class ColorfulImageColorization { /*


    • Instantiates a new colorful image colorization. */ public ColorfulImageColorization() { AlgorithmiaClient client2 = null;

      try { final String input2 = "asteele"; client2 = Algorithmia.client("simZfaiX4KxPXKOSlt6TBV+Rdtl1"); final Algorithm algo = client2.algo("algo://deeplearning/ColorfulImageColorization/1.1.6"); final AlgoResponse result2 = algo.pipe(input2); System.out.println(result2.asJsonString()); } catch (APIException | AlgorithmException ex1) { ex1.printStackTrace(); }

      try { // final AlgorithmiaClient client = Algorithmia.client("Simple // simZfaiX4KxPXKOSlt6TBV+Rdtl1"); // final Algorithm algo = // client.algo("algo://deeplearning/ColorfulImageColorization/1.1.6"); final byte[] input = Files.readAllBytes(new File("./images/ExploreBerlinTrip73-018-L.jpg").toPath()); final AlgoResponse result = client2.algo("algo://deeplearning/ColorfulImageColorization/1.1.6").pipe(input); final byte[] buffer = result.as(new TypeToken<byte[]>() { }); // -> [byte array] final FileOutputStream fos = new FileOutputStream("./images/ExploreBerlinTrip73-018-L.png"); fos.write(buffer); fos.close(); } catch (AlgorithmException | IOException ex) { ex.printStackTrace(); } }

    /**


    • The main method.
    • @param args
    •        the arguments
      

    */ public static void main(final String[] args) { final ColorfulImageColorization colorfulImageColorization = new ColorfulImageColorization(); } }

==============================================================================

v1.0.10 Stack trace:

Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:666) at com.algorithmia.client.HttpClient.(HttpClient.java:72) at com.algorithmia.AlgorithmiaClient.(AlgorithmiaClient.java:19) at com.algorithmia.Algorithmia.client(Algorithmia.java:52) at com.steele.algorithmia.ColorfulImageColorization.(ColorfulImageColorization.java:32) at com.steele.algorithmia.ColorfulImageColorization.main(ColorfulImageColorization.java:67)

==============================================================================

v1.0.12 Stack trace:

Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:666) at com.algorithmia.client.HttpClient.(HttpClient.java:78) at com.algorithmia.AlgorithmiaClient.(AlgorithmiaClient.java:19) at com.algorithmia.Algorithmia.client(Algorithmia.java:49) at com.steele.algorithmia.ColorfulImageColorization.(ColorfulImageColorization.java:32) at com.steele.algorithmia.ColorfulImageColorization.main(ColorfulImageColorization.java:67)

==============================================================================

v1.0.13 Stack trace:

Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:666) at com.algorithmia.client.HttpClient.(HttpClient.java:81) at com.algorithmia.AlgorithmiaClient.(AlgorithmiaClient.java:19) at com.algorithmia.Algorithmia.client(Algorithmia.java:49) at com.steele.algorithmia.ColorfulImageColorization.(ColorfulImageColorization.java:32) at com.steele.algorithmia.ColorfulImageColorization.main(ColorfulImageColorization.java:67)

============================================================================== package com.steele.algorithmia;

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException;

import com.algorithmia.APIException; import com.algorithmia.AlgorithmException; import com.algorithmia.Algorithmia; import com.algorithmia.AlgorithmiaClient; import com.algorithmia.algo.Algorithm; import com.algorithmia.data.DataAcl; import com.algorithmia.data.DataAclType; import com.algorithmia.data.DataDirectory;

public class DataAPI { public static void main(final String[] args) throws APIException { // write your code here final AlgorithmiaClient client = Algorithmia.client("simZfaiX4KxPXKOSlt6TBV+Rdtl1"); // Set your Data URI final DataDirectory nlp_directory = client.dir("data://asteele/nlp_directory"); // Create your data collection if it does not exist try { if (!nlp_directory.exists()) { nlp_directory.create(); } } catch (final APIException e) { e.printStackTrace(); } // Create the acl object and check if it's the .MY_ALGOS default setting final DataAcl acl = nlp_directory.getPermissions();

    if (acl.getReadPermissions() == DataAclType.MY_ALGOS) {
        System.out.println("acl is the default permissions type

MY_ALGOS"); }

    // Update permissions to private
    try {
        nlp_directory.updatePermissions(DataAcl.PRIVATE);
        if (acl.getReadPermissions() == DataAclType.MY_ALGOS) {
            System.out.println("acl is the default permissions type

MY_ALGOS"); } } catch (final APIException e) { e.printStackTrace(); }

    final String local_file = "local_path_to_your_file/jack_london.txt";
    try {
        nlp_directory.putFile(new File(local_file));
    } catch (final FileNotFoundException e) {
        e.printStackTrace();
    }
    final String text_file =

"data://asteele/nlp_directory/jack_london.txt"; try { if (client.file(text_file).exists()) { final String input = client.file(text_file).getString(); final Algorithm summarizer_algo = client.algo("nlp/Summarizer/0.1.3"); final String result = summarizer_algo.pipe(input).asString(); System.out.println(result); } else { System.out.println("Please check that your file exists"); } } catch (final IOException e) { e.printStackTrace(); } catch (final AlgorithmException e) { e.printStackTrace(); } } }

On Mon, Sep 4, 2017 at 7:29 PM, James Athappilly [email protected] wrote:

I've looked at the apache http client code and it should work if the two are unset. Was the error exactly the same in each case?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/algorithmiaio/algorithmia-java/issues/12#issuecomment-327042927, or mute the thread https://github.com/notifications/unsubscribe-auth/AeJeiZWwf1r3SCxSxhVX-9g7GZSclYyvks5sfJXWgaJpZM4PLi2R .

alfredsteele avatar Sep 05 '17 01:09 alfredsteele

This appears to be a problem with dependency resolution pulling in different versions of apache http client or its dependencies. @alfredsteele can you send you ivy/maven/gradle/sbt (whichever) file so I can try to repro?

platypii avatar Sep 05 '17 22:09 platypii

Attached is a screen capture of the jar files I am using with version numbers. I also attached the two test programs that won't run.

Al

On Tue, Sep 5, 2017 at 5:29 PM, Kenny [email protected] wrote:

This appears to be a problem with dependency resolution pulling in different versions of apache http client or its dependencies. @alfredsteele https://github.com/alfredsteele can you send you ivy/maven/gradle/sbt (whichever) file so I can try to repro?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/algorithmiaio/algorithmia-java/issues/12#issuecomment-327321727, or mute the thread https://github.com/notifications/unsubscribe-auth/AeJeiTSM4KMX3tlfO04mxatHSkehYjeGks5sfctAgaJpZM4PLi2R .

alfredsteele avatar Sep 06 '17 02:09 alfredsteele

I don't think the attachment came through, try posting directly on the github website?

kennydaniel avatar Sep 06 '17 03:09 kennydaniel