Abbot.8496:

This isn’t strictly related to the API, but this is where all the cool kids hang out so I’m posting here.

I’m currently building some automated tools for guild management using the information from the Achievements Leaderboard page. The program first needs to log in, however. Looking at the sign-in page, the form submits an ‘email’ field and a ‘password’ field via POST method.

When attempting to log in, I get back an error 400 (bad request) in response. Any ideas on how to diagnose the issue?

For reference, python code is as follows:


        import Request

        url = "https://account.guildwars2.com/login"
        content_type = 'text/html'
        payload = {"email" : username, "password" : password}
        headers2 = {"User-Agent" : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
                    "Content-Type" : content_type,
                    }
        
        s = Session()
        req = Request ('POST', url, data=payload, headers=headers2)
        prepped = req.prepare()
        resp = s.send(prepped)

Abominable Snowman.2036:

Well, first, your content-type is off (it should be application/x-www-form-urlencoded), but second, the login page seems to check the Referer. Simply adding

"Referer": url,

to your headers2 dict would do the trick.

Healix.5819:

This should help you answer any questions:

http://code.google.com/p/gw2-lastonline-leaderboards/

For logging in specifically.

Abbot.8496:

Thanks for the references, Healix. Those will come in handy.

Snowman, adding the entry to the dictionary was just the trick. How did you know about or where did you find reference to “Referer”?

Healix.5819:

How did you know about or where did you find reference to “Referer”?

When making a login script, you simply replicate the headers your web browser would send. Discovering that the referrer is required is simply a task of trial and error.