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
Create a maven project
Add this maven dependency
<dependency>
<groupId>com.algorithmia</groupId>
<artifactId>algorithmia-client</artifactId>
<version>[,1.1.0)</version>
</dependency>
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
Given the current date, 2nd July 2019, they published version 1.0.16 that fix such error.
Related
I am unsure about what the error might be, any kind of help is appreciated.
I am trying to use - https://github.com/SpoonLabs/flacoco I clonned the repository and then
created a maven project through eclipse IDE and added the dependencies in the Pom file however when I create a main java file with the code below obtained from their video - https://www.youtube.com/watch?v=RFRyvQuwRYA&ab_channel=DavideGinelli and try to run it. It does not detect any tests. It displays the following.
[30] INFO CoverageRunner - Tests found: 0
[30] INFO CoverageRunner - Tests executed: 0
This is the code in my main.
package demoproject1;
import java.io.IOException;
import java.util.Map;
import fr.spoonlabs.flacoco.api.Flacoco;
import fr.spoonlabs.flacoco.api.result.FlacocoResult;
import fr.spoonlabs.flacoco.api.result.Suspiciousness;
import fr.spoonlabs.flacoco.core.config.FlacocoConfig;
import spoon.reflect.code.CtStatement;
public class Main {
public static void main(String[] args) throws IOException {
FlacocoConfig config = new FlacocoConfig();
config.setProjectPath("C:\\Users\\A\\Documents\\GitHub\\flacoco\\examples\\math_70"); //./examples/math_70
config.setComputeSpoonResults(true);
Flacoco flacoco = new Flacoco(config);
FlacocoResult result =flacoco.run();
Map<CtStatement, Suspiciousness> spoonMap = result.getSpoonSuspiciousnessMap();
for(Map.Entry<CtStatement, Suspiciousness> entry : spoonMap.entrySet()){
System.out.println(entry.getKey().getPosition()+":"+ entry.getValue().getScore());
}
}
}
I am unsure about what the error might be, any kind of help is appreciated.
I was also confused by this, but pretty sure you have to build the project you are trying to test. As per the paper:
"FLACOCO detects the tests to be executed and analyzed by scanning the compiled classes" (flacoco paper)
I was getting the same error, until I ran
mvn install
in the repository I was trying to test (in this case, it was examples/exampleFL1/FLtest1. Not sure if the authors just forgot to mention this explicitly (maybe they thought it would be obvious) or if they just had already built the projects they were testing. But, this is what worked for me.
I'm trying to use Kohsuke's GitHub API for Java. I'm trying to connect to an Enterprise GH instance just to read some basic information about repos and, if possible, install GitHub Apps.
I'm a total beginner with Java. I've managed to add the JAR from the developer to my project and instantiate a few classes, but I can't figure out how to specify a URL for a repository to authenticate, much less get information or install an GitHub app through code.
Here is what I've put together so far, but functionally does nothing:
import org.kohsuke.github.GHAppInstallation;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import org.kohsuke.github.GHRepository;
public class appinstaller extends GHAppInstallation {
public static void main(String[] args) throws java.io.IOException {
System.out.println("Hello World!"); // Display the string.
GitHub github = new GitHubBuilder().withPassword("name", "xyz").build();
String name = new GHRepository().getFullName();
GitHub github2 = GitHub.connect();
GHRepository repo = github.getRepository()
// GHRepository repo = github.createRepository(
// "new-repository","this is my new repository",
// "https://www.kohsuke.org/",true/*public*/);
// repo.addCollaborators(github.getUser("abayer"),github.getUser("rtyler"));
// repo.delete();
}
}
There aren't any good reference examples for Java beginners in the API documentation (https://github-api.kohsuke.org/). Could somebody with some experience and know-how get me started on basic authentication to an existing repo?
Thank you!
Here is the code that's expected to produce error:
public class App {
public static void main (String[] args) {
tick();
}
public static void tick () {
System.out.print("hi");
Note that the closing angled bracket of both, the method tick() and class App is missing. Although the IDE indicates this error while writing code, this compiles and runs just fine. It doesn't look like an issue with Java (or my OS) as doing javac in the command line surely does fail.
What's even funnier...the following code throws a Runtime exception after successfully executing tick():
public class App {
public static void main (String[] args) {
tick();
public static void tick () {
System.out.print("hello..");
Here I skipped closing bracket of main too.
I have installed the development version of Netbeans that has support for Java 9.
[This is a comment more than an answer, but I wanted to include screen shots to show that I cannot reproduce either issue.]
An interesting problem. I just downloaded the most recent nightly build (NetBeans Dev 201803060002) and built your code using Oracle JDK 9.04.
Neither of your code examples would compile for me. For the first example the error for the final line was "reached end of file while parsing System.out.print("hi");". Here is a screen shot:
For the second example, where you removed the closing bracker of main() the additional error reported was "illegal start of expression public static void tick () {":
I suggest that you try the following:
Create a new project and new class "App2" to see if you can replicate the issue with that same version of NetBeans.
If you cannot then review why App compiles and App2 does not.
If you can replicate the problem then download the most recently nightly build to see if you can still replicate the problem (i.e. Invalid source code compiles cleanly). If you cannot then I don't think it is worth raising a bug report or spending further time on the matter.
However, if you can replicate the problem then by all means raise a bug report. But I strongly recommend being able to replicate the failure before doing that. Otherwise you are likely to get a WORKSFORME response if the NetBeans team cannot replicate the issue.
One more thing: it would be helpful to update your OP with the stack trace for that RuntimeException, which you should also include in your bug report.
Ah...I see it now. At some point of time I checked the "Always run without asking" checkbox and since then my IDE is ignoring all the compile time errors without any warnings.
Sorry guys...my bad.
I have a little problem. I´ve been trying to use different libraries to produce a json token and now I'm using JJWT from Stormpath. They have tutorials well explained. But my problem is, when I try to run the String method in a "public static void main" method, I get a runtime or class error. In their official website says there is a requeriment that the jackson library must being newer than Version 2.8. So I downloaded such library.
Here my source code:
package org.comunidadIT.proyecto.accesoDatos;
import java.security.Key;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
public class ValidarToken {
public String token(){
// We need a signing key, so we'll create one just for this example. Usually
// the key would be read from your application configuration instead.
Key key = MacProvider.generateKey();
String compactJws = Jwts.builder()
.setSubject("Joe")
.signWith(SignatureAlgorithm.HS512, key)
.compact();
return compactJws;
}
public static void main(String args[]){
ValidarToken t= new ValidarToken();
System.out.println(t.token());
}
}
The console show following error message:
Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS
at com.fasterxml.jackson.annotation.JsonInclude$Value.<clinit>(JsonInclude.java:204)
at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:44)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:549)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:465)
at io.jsonwebtoken.impl.DefaultJwtBuilder.<clinit>(DefaultJwtBuilder.java:42)
at io.jsonwebtoken.Jwts.builder(Jwts.java:116)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.token(ValidarToken.java:16)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.main(ValidarToken.java:27)
Image from maven dependencies where appears to be fine with jackson
Image from the console with erros
As you can see the jackson dependencies appears to be fine.
Also I aatached more libreries to the build-path on reference libraries, but they are outside from the pom.xml.
What do I do wrong?
Thank you
I answer myself so perhaps someone could have the same problem.
I've been with this problem about a month, until I got balls to delete some old libraries located in my project.
The problem appeared to be that I declared a Maven dependecy with jackson 2.8.2 or later and in the 'reference libraries' I had libraries lowers than 1.9, when I removed from my Build-Path the problem was gone. And now I can see the String Token.
This is the picture with the problem solved.
Thank you.
I am new to boilerpipe. I tried to run sample code given on their website:
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.extractors.DefaultExtractor;
public class TESTURLBOILERPIPE {
public static void main(String[] arges) throws Exception
{
final URL url = new URL(
"http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en");
ArticleExtractor ae = new ArticleExtractor();
System.out.println(ae.INSTANCE.getText(url));
}
}
I have added all the required jar files to the class path, however I get the exception:
Exception in thread "main" java.lang.IllegalArgumentException: usage: supply url to fetch
at org.jsoup.helper.Validate.isTrue(Validate.java:45)
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:26)
I don't know Boilerpipe, but are you sure you are trying to run the correct Java class? The stack trace looks like you are trying to run HtmlToPlainText (without arguments, thus the exception), but from the code you posted I think you would like to run your TESTURLBOILERPIPE class.
Try using a python wrapper. It takes care of all the dependencies, though you might have to install jpype manually (that source code is on sourceforge).
https://github.com/misja/python-boilerpipe