Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot upload file #38

Closed
ghost opened this issue Nov 24, 2014 · 13 comments
Closed

cannot upload file #38

ghost opened this issue Nov 24, 2014 · 13 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Nov 24, 2014

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
Copy link
Owner

eldur commented Nov 24, 2014

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.

eldur added a commit that referenced this issue Nov 24, 2014
@eldur eldur added the review label Nov 24, 2014
@ghost
Copy link
Author

ghost commented Nov 25, 2014

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

@eldur
Copy link
Owner

eldur commented Nov 25, 2014

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

@ghost
Copy link
Author

ghost commented Nov 25, 2014

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
Copy link
Owner

eldur commented Nov 26, 2014

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
Copy link
Author

ghost commented Nov 26, 2014

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

@eldur eldur added enhancement and removed review labels Nov 26, 2014
@eldur eldur self-assigned this Nov 26, 2014
@eldur
Copy link
Owner

eldur commented Nov 26, 2014

I hope this helps

@ghost
Copy link
Author

ghost commented Nov 27, 2014

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
Copy link
Owner

eldur commented Nov 27, 2014

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.. 😉

@eldur
Copy link
Owner

eldur commented Dec 7, 2014

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

@ghost
Copy link
Author

ghost commented Dec 8, 2014

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 added a commit that referenced this issue Dec 8, 2014
eldur added a commit that referenced this issue Dec 8, 2014
@eldur
Copy link
Owner

eldur commented Dec 8, 2014

try again please, your snippet is correct.

@ghost
Copy link
Author

ghost commented Dec 10, 2014

Yeap works! Thank you a lot!!

@ghost ghost closed this as completed Dec 10, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant