Getting 200 ok response but username and password fields are empty its again redirecting to login page

86 Views Asked by At

Getting 200 ok response but username and password fields are empty its again redirecting to login page can you help me on this?

import requests
from bs4 import BeautifulSoup

header = {
    'User-Agent': 'Mozilla/5.0   (Windows NT 10.0; Win64; x64)  AppleWebKit/537.36 (KHTML, like  Gecko) Chrome/118.0.0.0 Safari/537.36   Edg/118.0.2088.61'
}

Payload = {
    "utf8": "✓",
    "spree_user[email]":     "[email protected]",
    "spree_user[password]":   "Qwerty@123",
    "spree_user[remember_me]": "0",
    "commit": "Login",
}

with requests.Session() as ses:
    Url = "https://xxxxxxxxxx.com"
    Req = ses.get(Url)
    soup = BeautifulSoup(Req.content,   'html5lib')
    print(Req.content)
    Payload['authenticity_token'] = soup.find('meta', {'name': 'csrf-token'})['content']
    res = ses.post('http://xxxxxxxxxx.com/login', data=Payload, headers=header)
    print(res.content)

Note: Username/password are correct but still facing same issue.

1

There are 1 best solutions below

0
Abdul Khadar On BEST ANSWER

Well, I figured out myself the URL I provided was 'http://xxxxxxxxx.com/login,'[http] but it should be 'https://xxxxxxxxx.com/login.'[https]. Here is the modified code:

res = ses.post('https://xxxxxxxxx.com/login', data=Payload, headers=header)