eldur / jwbf

Java Wiki Bot Framework is a library to maintain Wikis like Wikipedia based on MediaWiki.
http://jwbf.sourceforge.net/
Apache License 2.0
78 stars 33 forks source link

cannot upload file #38

Closed ghost closed 9 years ago

ghost commented 10 years ago

I'm trying to upload a image to Wikimedia Commons. I already edited some article with your library, works fine now. By executing the following snippet no exceptions appear after network traffic has calm down. No new image is viewable on Commons.

HttpActionClient client = HttpActionClient.builder() //
    .withUrl("https://commons.wikimedia.org/w/") //
    .withUserAgent("BotName", "0.1", "jotpe") //
    .withRequestsPerUnit(60, TimeUnit.MINUTES) //
    .build();
MediaWikiBot wikiBot = new MediaWikiBot(client);
wikiBot.login("jotpe", "yyyy");
File f = new File("/tmp/Roof terrace Hostel.JPG");
SimpleFile file = new SimpleFile(f.getAbsolutePath());
file.addText(i.generateCommonsTemplate());
wikiBot.getPerformedAction(new FileUpload(file, wikiBot));

Is this related to Token handling #28 ? The last stament was:

 97371 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << MediaWiki-API-Error: mustposttoken
eldur commented 10 years ago

Hmm maybe. With the latest mediawiki version that is downloadable form mediawiki.org (1.23) I've no problems with uploading new images.

I could offer a line of debug logging to get more details about this problem.

ghost commented 10 years ago

They use version 1.25, see http://commons.wikimedia.org/wiki/Special:Version

eldur commented 10 years ago

I know, have you tried to enable debug logging with the patch above?

ghost commented 10 years ago

Yes. Guess log level should be higher.

65549 [net.jotpe.HelperFirstUpload.main()] DEBUG net.sourceforge.jwbf.mediawiki.actions.editing.FileUpload  - <?xml version="1.0"?><api servedby="mw1189"><error code="mustposttoken" info="The &#039;token&#039; parameter was found in the query string, but must be in the POST body" xml:space="preserve">See https://commons.wikimedia.org/w/api.php for API usage</error></api>
eldur commented 10 years ago

A first try to to follow this error hint and move the 'token' to post body causes a regression with 1.23 and older.

ghost commented 10 years ago

Clearly, but don't know how. Maybe its more easy for you.

eldur commented 10 years ago

I hope this helps

ghost commented 10 years ago

Nearly, now I get a badtoken error. And there is a test failure.

 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << HTTP/1.1 200 OK
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Server: nginx/1.1.19
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Date: Thu, 27 Nov 2014 05:46:46 GMT
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Content-Type: text/xml; charset=utf-8
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Content-Length: 163
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Connection: keep-alive
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << X-Content-Type-Options: nosniff
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Cache-control: private
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << MediaWiki-API-Error: badtoken
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << X-Frame-Options: SAMEORIGIN
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Content-Encoding: gzip
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Vary: Accept-Encoding
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << X-Varnish: 191365746, 372513418, 1527940033
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Via: 1.1 varnish, 1.1 varnish, 1.1 varnish
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Accept-Ranges: bytes
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << Age: 0
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << X-Cache: cp1055 miss (0), amssq51 miss (0), amssq39 frontend miss (0)
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.headers  - http-outgoing-0 << X-Analytics: php=zend
 93146 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.impl.execchain.MainClientExec  - Connection can be kept alive indefinitely
 93147 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager  - Connection [id: 0][route: {s}->https://commons.wikimedia.org:443] can be kept alive indefinitely
 93147 [net.jotpe.HelperFirstUpload.main()] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager  - Connection released: [id: 0][route: {s}->https://commons.wikimedia.org:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
 93147 [net.jotpe.HelperFirstUpload.main()] DEBUG net.sourceforge.jwbf.mediawiki.actions.editing.FileUpload  - <?xml version="1.0"?><api servedby="mw1202"><error code="badtoken" info="Invalid token" xml:space="preserve">See https://commons.wikimedia.org/w/api.php for API usage</error></api>

 93151 [net.jotpe.HelperFirstUpload.main()] ERROR net.sourceforge.jwbf.mapper.XmlConverter  - badtoken: Invalid token
 [WARNING] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
    at java.lang.Thread.run(Thread.java:745)
Caused by: net.sourceforge.jwbf.mediawiki.actions.util.ApiException: API ERROR CODE: badtoken VALUE: Invalid token
    at net.sourceforge.jwbf.mapper.XmlConverter$1.applyNonnull(XmlConverter.java:47)
    at net.sourceforge.jwbf.mapper.XmlConverter$1.applyNonnull(XmlConverter.java:39)
eldur commented 10 years ago

It's reproduceable with the release of mw 1.24 from yesterday (2014-11-26), I try to check this in the next days. Or if you want to help with a patch.. :wink:

eldur commented 9 years ago

does this patch help? I tend to close this issue and create an new release as fast as possible.

ghost commented 9 years ago

Yes, your patch works! But my article text wasn't uploaded. I did it with

SimpleFile file = new SimpleFile(f.getAbsolutePath());
        file.addText(israelnationaltrail.generateCommonsTemplate());
        wikiBot.getPerformedAction(new FileUpload(file, wikiBot));

Is this the right way?

eldur commented 9 years ago

try again please, your snippet is correct.

ghost commented 9 years ago

Yeap works! Thank you a lot!!