Using python request library to login to site

I looked at many SO threads on how to create a session using the requests library, but none of the methods that I tried actually logged in. I have very little experience with web design and protocols, so please indicate any basics that I may need to understand. That's what I'm doing:

import requests EMAIL = 'my_email' PASSWORD = 'my_pw' URL = 'https://account.guildwars2.com/login' session = requests.session() login_data = dict(username=EMAIL, password=PASSWORD) r = session.post(URL, data=login_data) req = session.get('https://leaderboards.guildwars2.com/en/na/achievements/guild/Darkhaven%20Elite') print req.content 

The content that I see is the content that I will see if I do not log in.

Is there something wrong with my syntax or a problem caused by the way access to the login page is configured?

+4
source share
1 answer

@DanAlbert pointed out that I told you to use HTTP Auth, which is not what you are trying to do. I assumed that everything looked right, that you might need an HTTP out.

However, looking at the form, it looks like you are simply using the wrong variable name in your dict:

 import requests s = requests.session() login_data = dict(email='email', password='password') s.post('https://account.guildwars2.com/login', data=login_data) r = s.get('https://leaderboards.guildwars2.com/en/na/achievements/guild/Darkhaven%20Elite') print r.content 

If you look at the form, it expects the variables "email" and "password". You have a "username" and "password"

Anyway, HTH

+8
source

Source: https://habr.com/ru/post/1485126/


All Articles