XZise added a comment.

(This is shamelessly copied from 
https://phabricator.wikimedia.org/T112405#1635010 so logging in and getting the 
token works the same)

Okay here are the `curl` commands to reproduce it. If you are logged in you can 
skip the two block. If you have already an CSRF token you can also skip the 
third block. The login will store the cookie into the cookie.lwp file.

Login
-----

  $ PASS=
  $ NAME=
  $ curl -b cookie.lwp -c cookie.lwp -d action=login -d lgname=$NAME -d 
lgpassword=$PASS -d format=json https://test.wikipedia.org/w/api.php
  
{"login":{"result":"NeedToken","token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","cookieprefix":"testwiki","sessionid":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}

Now use the token in the next request and you are logged in:

  $ curl -b cookie.lwp -c cookie.lwp -d action=login -d lgname=$NAME -d 
lgpassword=$PASS -d lgtoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -d format=json 
https://test.wikipedia.org/w/api.php
  
{"login":{"result":"Success","lguserid":x,"lgusername":"x","lgtoken":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","cookieprefix":"testwiki","sessionid":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}



CSRF token
----------

Now request the CSRF token (I request the userinfo too, to verify that I'm 
logged in):

  $ curl -b cookie.lwp -d action=query -d meta="userinfo|tokens" -d type=csrf 
-d format=json https://test.wikipedia.org/w/api.php 
  {"batchcomplete":"","query":{"userinfo":{"id":x,"name":"x"},"tokens":
  {"csrftoken":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+\\"}}}
  $ TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+\\"



Upload
------

So now we get to this bug. I'm using the `MP_sounds.png` test file and split it 
into two chunks:

  $ wget 
https://raw.githubusercontent.com/wikimedia/pywikibot-core/master/tests/data/images/MP_sounds.png
  $ split -a 1 --numeric-suffixes=1 -b 1024 MP_sounds.png c1024.
  $ curl -b cookie.lwp -F format=json -F action=upload -F stash=1 -F 
filesize=1276 -F filename=File:MP_sounds-pwb.png -F token=$TOKEN -F offset=0 -F 
chunk=@c1024.1 https://test.wikipedia.org/w/api.php
  
{"upload":{"result":"Warning","warnings":{"badfilename":"MP_sounds-pwb.png","exists":"MP_sounds-pwb.png"},"filekey":"13fzjy4zqofo.ty2ufl.28718.png","sessionkey":"13fzjy4zqofo.ty2ufl.28718.png"}}
  $ FILEKEY=13fzjy4zqofo.ty2ufl.28718.png

It is important to store the filekey. We can also verify that something was 
actually uploaded using `query+stashimageinfo`:

  $ curl -b cookie.lwp -d format=json -d action=query -d prop=stashimageinfo -d 
siifilekey=$FILEKEY -d siiprop="size|sha1|timestamp" 
https://test.wikipedia.org/w/api.php
  
{"batchcomplete":"","query":{"stashimageinfo":[{"timestamp":"2015-09-13T10:06:46Z","size":1024,"width":24,"height":27,"sha1":"3503db342c8dfb0a38db0682b7370ddd271fa163"}]}}
  $ sha1sum c1024.*
  3503db342c8dfb0a38db0682b7370ddd271fa163  c1024.1
  2ed6566594d8893d55f5fbbc279f096ee157e28d  c1024.2

So the uploaded chunk seems fine, now continue uploading the second chunk:

  $ curl -b cookie.lwp -F format=json -F action=upload -F stash=1 -F 
filesize=1276 -F filename=File:MP_sounds-pwb.png -F token=$TOKEN -F offset=1024 
-F filekey=$FILEKEY -F chunk=@c1024.2 -F ignorewarnings=1 
https://test.wikipedia.org/w/api.php
  {"servedby":"mw1017","error":{"code":"stashfailed","info":"No chunked upload 
session with this key","*":"See https://test.wikipedia.org/w/api.php for API 
usage"}}

And tada the error using CURL so pywikibot is not actually failing here.


TASK DETAIL
  https://phabricator.wikimedia.org/T112416

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: XZise
Cc: jayvdb, Matanya, Tgr, Aklapper, Steinsplitter, pywikibot-bugs-list, XZise, 
Bawolff, Fabrice_Florin, Anomie, Legoktm



_______________________________________________
pywikibot-bugs mailing list
pywikibot-bugs@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to