Iam trying to login to a web page using pythons requests module. I captured the post request when submitting the Login form using chrome as well as rechecking the code of that form. (Website as well as the parameters are mentioned in the code snippet below)
Based on someones post i was able to create a python snippet that tries to login and access protected content but for some reason this is not working as intended.
Here is my python snippet:
import requests
LOGIN = 'https://www.hackthis.co.uk/index.php'
PROTECTED_PAGE = 'https://www.hackthis.co.uk/news'
payload = {
'username': 'VALIDUSERNAME',
'password': 'VALIDPASSWORD'
}
with requests.session() as s:
s.post(LOGIN, data=payload)
response = s.get(PROTECTED_PAGE)
print(response.text)
Even though i send the post request with the required payload iam not able to access protected content. The response HTML code contains the login form as well as a note that iam not allowed to access that content without logging in.
What do i miss here?
Edit:
Thanks for the very helpful answers! Pretty stupid mistake was made. I forgot the ?login part of the URL. Here is a working code snippet for subsequent questions on that topic (tested, works as intended):
import requests
LOGIN = 'https://www.hackthis.co.uk/index.php?login'
PROTECTED_PAGE = 'https://www.hackthis.co.uk/news'
payload = {
'username': 'VALIDUSERNAME',
'password': 'VALIDPASSWORD'
}
with requests.session() as s:
s.post(LOGIN, data=payload)
response = s.get(PROTECTED_PAGE)
print(response.text)