Jeeva
Jeeva

Reputation: 1057

Python requests module Session seems not redirecting itself

I was trying to Login with python requests module but when I run the following code it just returning the same cookie, I checked the returning content its actually the Login form on all three requests, it seems that session not redirecting itself

any help? or any link to resources?

import requests

url = "http://challenge.anyms.me/simple-brute-force/"

wrong_payload = {"username": "safjh", "password": "aefyshjsk", "Login": "login"}
correct_payload = {"username": "admin", "password": "passw0rd", "Login": "login"}

s = requests.session()
for i in range(3):
    if (i == 1):
        r = s.post(url, data=correct_payload)
        for cookie in s.cookies:
            print (cookie.name, cookie.value)
    else:
        r = s.post(url, data=wrong_payload)
        for cookie in s.cookies:
            print (cookie.name, cookie.value)

Upvotes: 0

Views: 99

Answers (1)

Harald Nordgren
Harald Nordgren

Reputation: 12381

Looking at the anyms.me link, the correct form of the payload is capital L on the value and regular on the key, so

"login": "Login"

Using that payload instead, you get a new url and a 302 redirect response in the history:

>>> r.url
'http://challenge.anyms.me/simple-brute-force/home/'
>>> r.history
[<Response [302]>]

Upvotes: 1

Related Questions