[19:19:31] hello [19:20:54] i'm facing a little problem with the mediawiki api, i own a wiki bot which cannot upload files [19:21:21] and the error isn't an object, it's like the html source code of the wiki's api page, so it isn't quite helpful [19:21:51] i use the nodejs "mwbot" library, if it's any help [19:23:19] it would probably help if you'd tell what is it that you are trying to do, and what the error message is [19:24:04] uploading a file through a bot [19:24:45] to what mediawiki version [19:26:31] 1.31.1 [19:26:34] Please provide clear and exact steps to reproduce. And if there is an error, please provide the exact error. [19:27:48] 1) install nodejs and with it, the mwbot module 2) login as a bot account through the module 3) attempt to upload a file [19:29:17] N_tonio36: Did you see the HTML returned by the error? What kind of error is it? Maybe it's not MediaWiki, but an error generated or masked by the webserver itself [19:29:43] i'll create a text file of the error [19:31:42] https://ufile.io/refv8 [19:32:10] the wiki is french, mind you [19:33:03] please use a pastebin [19:33:13] https://dpaste.de [19:33:18] fine [19:33:36] https://dpaste.de/aUMo [19:33:57] forgot to set the syntax highlight --' [19:34:53] Poképédia, I know this one ;) [19:34:54] looks like it gives you somekind of API help page [19:35:08] yup, it is the API help page [19:35:38] Does it happen with every upload, or only a particular file? [19:35:44] every upload [19:35:50] literally, every single upload [19:35:51] does your bot work otherwise? [19:35:54] yup [19:36:03] what endpoint are you using to upload files? [19:36:12] pokepedia.fr/api.php [19:36:20] basically the same as everything else [19:36:28] as every other task, i mean [19:37:19] You've probably read this, right? https://www.mediawiki.org/wiki/API:Upload [19:37:48] yup i did [19:38:20] do you have that token present? [19:38:27] yup [19:38:42] or else it would clearly tell me that i need a token for my requests [19:38:50] Be sure the endpoint is, exactly "https://www.pokepedia.fr/api.php". If you miss the www. prefix, or you're not using https:, the server may force you a redirect and you lose the POSTed data [19:38:52] (at least the error would be a clear one x°) [19:39:21] it is exactly as mentioned, https://www.pokepedia.fr/api.php [19:39:44] could it be disabled, file upload? [19:39:57] file uploads aren't disabled, no [19:40:32] the bot also has the rights of an identified user, including uploading files, so it's not a permission issue [19:40:52] In the api, any error or permission problem would give a error message with the chosen api format, either json or xml, not the HTML representation of it [19:40:54] well that help page certainly is not helpful. [19:41:04] my point exactly ^^" [19:41:28] It looks like the server is either doing a redirect to the api main page, or discarding all parameters/POST data [19:41:44] ...or there's a bug with the bot not sending them [19:41:54] not quite [19:42:20] i've printed the sent request to the console, it does include the parameters/post data, with the file content and whatnot [19:42:56] but if it's a server problem, shouldn't it mean that literally anyone can't upload files, bot or human? [19:43:29] Can you get the response from the server, without automatically following redirects? Just to be sure it doesn't send you a HTTP 302 response that redirects the bot to the api main page [19:43:58] The problem may be only on the api. Normal web uploads are not handled by the api [19:44:39] i see [19:49:21] i'll try intercepting the server replies, it's gonna take some time tho [19:49:27] hope you don't mind [19:49:29] ^^" [19:49:37] no problem [20:00:57] any other way we could try to debug? i'm not quite able to do it :s [20:01:56] what does the response say? [20:02:37] i wasn't able to intercept it ^^" [20:02:47] sorry, i messed up big time i know [20:02:53] no you did not [20:03:12] can you show the code? maybe we can help [20:06:40] oh interesting [20:06:54] guess the way to intercept incoming responses was right under my nose ^^" [20:07:18] alright so i tried a functioning query, and it showed me a proper server response [20:07:25] i'll pastebin it for reference [20:09:02] https://pastebin.com/k3fqLA7R sensitive details hidden, this is what i get when i login [20:10:41] aaaaaaaaaaand https://pastebin.com/Suw0XXjk straight from the server [20:10:55] yet again, it's the mediawiki api reference [20:10:57] --' [20:12:07] well your example doesn't show any params [20:12:18] also topic suggests to use dpaste.de [20:12:55] well, as i said, it was just a login [20:13:42] allow me to sidetrack just a bit, but what's the difference between pastebin and dpaste? [20:13:45] so what does the request for file uploads hold [20:14:17] the other one shows ads [20:14:38] mm fine [20:14:48] can you paste the request object? [20:14:55] alright [20:15:02] when you try to upload [20:16:26] side note, when i try to upload, the answer comes as a http request 200 code [20:16:38] with, you guessed it, the whole html deal [20:16:45] 200, not 302, strangely [20:19:07] https://dpaste.de/i7VW for the outgoing request [20:19:07] enable word wrap [20:24:51] "name":"token","value":false} [20:25:15] ..... oh [20:25:54] Gotta go to sleep, I hope you solve this problem! [20:26:07] cya, thanks ^^ [20:28:04] well uh [20:28:31] it hopelessly didn't work, even with a login before the upload attempt [20:28:58] login + token obtaining [20:30:42] Can you try debugging requests, with https://www.npmjs.com/package/request#debugging ?, the dpaste you posted seems to contain pre- or post-processed data wich may not be what is really going to the server [20:33:07] the dpaste is indeed the pre-processed data [20:33:15] i'll do as you suggested [20:37:42] https://dpaste.de/dGig [20:37:51] server answer [20:41:30] as you can see, it's a 200 status code, not 302 [20:41:49] N_tonio36: uh, be sure to log out inmediately, I forgot to say to remove the cookies from the request/response, which are there [20:42:58] i trust you don't mess with the cookies :) [20:43:21] but i'll remove them if that's a really big deal [20:44:07] Just log out and log in again [20:44:14] That will make that cookie invalid [20:44:22] okay [20:44:41] I see the problem here: The bot is sending content with "content-type":"application/x-www-form-urlencoded" [20:44:52] It should be multipart/form-data instead [20:45:58] Are you overriding it? Apparently by default it's set correctly https://github.com/Fannon/mwbot/blob/master/src/index.js#L632 [20:46:18] i don't remember touching it, but i'll double check [20:48:18] are content-type and mimeType different things? [20:50:07] I guess requests translates one to the other [20:50:23] (Note: I've never developed with nodejs) [20:52:05] as far as i can tell, the line you've shown matches what i currently have [20:52:52] give me some time, i have some digging to do [20:53:08] Oh, I mean if you passed a different content/type mimetype from the code that calls this [20:53:30] well, nope [20:54:50] but that "content-type": "application-whatever" actually piqued (if that's a word) my interest [20:55:14] i just have to find where does it get set, so i can override it into the proper value [20:55:42] probably an ugly hack but it should work [20:56:15] maybe something changed in the requests library for that header, and mwbot hasn't been updated [20:59:51] the content-type header should be set just like the user-agent, right? [21:00:29] like { method: 'POST', headers: { "content-type": "multipart/form-data", "User-Agent": "mwbot/whatever")}} [21:00:42] don't mind the ), typo [21:01:34] yes, it's a header. However, it also changes how the data is sent to the server. I'm not sure if the requests library will automatically convert that for you or needs an explicit parameter [21:02:02] well, i just printed out the outgoing request, aaand it only has the user agent set [21:02:22] on my level, at least [21:02:40] my guess is that it gets set by default to application/x-whatever [21:02:41] actually, seems to be a matter of what parameter name you use to send the data: https://stackoverflow.com/questions/49053193/nodejs-request-how-to-send-multipart-form-data-post-request [21:03:15] oh [21:03:18] interesting [21:12:54] alright so i got dirty and tried a workaround to include the proper content-type and follow the SO answer [21:13:20] and now, for the tryout [21:16:16] well, it still didn't work [21:16:26] let me print out a new response [21:17:25] ugh, the content-type is being overriden [21:18:06] https://dpaste.de/BEAb [21:19:22] :( [21:20:09] well, i guess i gotta reaaally get dirty and dig into the request module [21:21:14] at least i'm aware of the problem, that's a bit of progress i believe [21:34:51] oh i got an idea [21:35:08] freeze the request object, denying any change to id :D [21:35:10] it* [23:22:01] Does anyone here have any experience using the Comments extension? [23:24:15] Or ideas about putting a function call onto a page from a template?