skip to Main Content

I am trying to use the Python’s requests library to insert my credentials in a website. However i don’t know how to verify if the login is successful. The page that i am trying to insert my credentials is this. As i can see, the name of the username entry is username and the name of the password entry is passname from the HTML code (the form element). Here is the code that i use:

payload = {'username': 'my_username', 'passname': 'my_password'}
url = 'https://www.e-shop.gr/usr_login.phtml'
res = requests.post(url, data=payload, verify=False)
print(res.status_code)
print(res.history)

The status code of the response is 200 and the history is a list with a 302 response (redirection).

2

Answers


    1. check response body to see if anything wrong;
    2. usually after successful login, server will set cookie(or other header) with key "token" or other key meaning your auth. you could try to understand which one works by checking it by opening this website in browser, checking from login page to feature page. so here you could call another API which need authorization, with cookie from the login API response, after your code pasted here.
    Login or Signup to reply.
  1. You can check based on the status_code, if the status code is 200 then the login was successful. And also you can mixed it up based on the history redirection and validate either the token was in the response headers or body

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search