PDA

View Full Version : Upload Automation and Authorization



Socks the Fox
10-17-2014, 12:56 PM
Right. I'm trying to write a script to automatically upload a metric crapton of submissions for a friend, along with going through and adding/updating navigation because weasyl's folder nav is so very subpar for what we were expecting.

I can request pages, and submit forms, but I'm getting stuck at the login step. I keep getting the "nope, sorry. Doesn't look valid" response (which is frustratingly returned as "200 OK". No, it's not OK. Use 403 or something).

My current code does as follows:
Grab /signin
Stash away any cookies I got from the response
Parse out the data-csrf-token value
Submit a "application/x-www-form-urlencoded" with the token, username, password, referer fields filled (I'll probably dump referer if I can), and toss back any cookies

The response to that last step is where I get the nope page.

The User-Agent is "Weaslysphere/0.1"

How do I get a proper login done? I'm sure whatever it is I'm doing or not doing will cause problems with other forms as well.

I'm sure I'm doing something wrong (it took me a couple of hours to figure out I was replacing the output, not appending to it, when trying to get my multipart/form-data code working).

weykent
10-17-2014, 01:00 PM
you should probably look over http://projects.weasyl.com/weasylapi/ if you haven't already—POSTing to the login form is not the best way to issue authorized requests.

Socks the Fox
10-17-2014, 01:02 PM
Is there a way to upload or edit submissions via the API? Or does API authorization work for non-API pages?

weykent
10-17-2014, 01:08 PM
API authorization works for (almost) all pages. there's not yet any API endpoints which do writes (as opposed to the current read-only endpoints), but I believe there's a ticket open and work being done on it.

Socks the Fox
10-17-2014, 01:17 PM
Do I still need to worry about whatever's keeping me from logging in as far as it also keeping me from uploading things?

Edit: Never mind, just tried it. I wish I had known API keys worked on all pages from the beginning X3