wtekiela / opensub4j

Java library for communicating with opensubtitles.org XML-RPC API
Other
47 stars 19 forks source link

IllegalArgumentException when parsing response #22

Closed codesunshine closed 3 years ago

codesunshine commented 3 years ago
2020-09-28 14:02:44.742 8416-8447/com.subprj W/System.err: java.lang.IllegalArgumentException: field com.github.wtekiela.opensub4j.response.Response.status has type com.github.wtekiela.opensub4j.response.ResponseStatus, got java.lang.String
2020-09-28 14:02:44.742 8416-8447/com.subprj W/System.err:     at java.lang.reflect.Field.set(Native Method)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.github.wtekiela.opensub4j.impl.ResponseParser$FieldBindingTask.set(ResponseParser.java:208)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.github.wtekiela.opensub4j.impl.ResponseParser$FieldBindingTask.executePrimitiveFieldBinding(ResponseParser.java:140)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.github.wtekiela.opensub4j.impl.ResponseParser$FieldBindingTask.run(ResponseParser.java:109)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.github.wtekiela.opensub4j.impl.ResponseParser.bind(ResponseParser.java:62)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.github.wtekiela.opensub4j.impl.AbstractOperation.execute(AbstractOperation.java:24)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.github.wtekiela.opensub4j.impl.OpenSubtitlesClientImpl.login(OpenSubtitlesClientImpl.java:112)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at com.subprj.MainActivity$InitOpenSubTask.run(MainActivity.java:98)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2020-09-28 14:02:44.743 8416-8447/com.subprj W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2020-09-28 14:02:44.744 8416-8447/com.subprj W/System.err:     at java.lang.Thread.run(Thread.java:764)
wtekiela commented 3 years ago

Hi @codesunshine, thanks for opening this issue.

I'll be glad to help you, but to do that I think I will need a bit more details. If you could put a bit more effort in describing your issue than just pasting a stacktrace. it would be really appreciated. For example: when do you get this? Can you provide a code snippet that you are running that throws this exception? Have you done any investigation yourself?

Also, PRs are welcome :)

Thanks

codesunshine commented 3 years ago

Thank you very much!

I got an error while executing the login method。

This is code:

URL serverUrl = new URL("https", "api.opensubtitles.org", 443, "/xml-rpc");

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(serverUrl);
config.setConnectionTimeout(30000);
config.setReplyTimeout(1000);
config.setGzipCompressing(true);

OpenSubtitlesClient osClient = new OpenSubtitlesClientImpl(config);
// logging in
Response response = osClient.login(
                        "my name", "my password", "zh",
                        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36");

I registered on https://www.opensubtitles.org/zh

wtekiela commented 3 years ago

Hi @codesunshine thanks for providing the code sample. There are two problems - one with the library, and one with your code.

Firstly, the library should not fail at parsing the response, clearly a bug that needs fixing.

However, the root cause of this is that opensubtitles api responds with:

12:15:04.385 [main] DEBUG c.g.w.o.x.c.RetryableXmlRpcClient - Response: {seconds=0.001, status=parse error. not well formed}

This is because your XmlRpcClientConfigImpl is improper, you set config.setGzipCompressing(true); which does not work without config.setEnabledForExtensions(true);.

Sample config that should work:

        XmlRpcClientConfigImpl xmlRpcClientConfig = new XmlRpcClientConfigImpl();
        xmlRpcClientConfig.setServerURL(serverUrl);
        xmlRpcClientConfig.setEnabledForExtensions(true);
        xmlRpcClientConfig.setGzipCompressing(true);
        xmlRpcClientConfig.setGzipRequesting(true);

Another problem is with your user agent. According to opensubtitles documentation, you should be using TemporaryUserAgent for your tests unless you have applied with opensubtitles for your custom user agent.