Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Requests login failure
#1
Hello, i'm trying to learn to use the requests module. I have written the following code, but it doesnt login to my account and returns an error.

import requests

url = 'https://python-forum.io/member.php?action=login'
 
username	= 'test'
password 	= '*******'

with requests.Session() as session:
	session.get(url)
	csrftoken = session.cookies['csrftoken']
	login_data = dict(csrfmiddlewaretoken=csrftoken, username=username, password =password, next='/' )
	session.post(url, data=login_data, headers={'Referer' : "https://python-forum.io"})
	page = session.get('https://python-forum.io/usercp.php')
Im getting the following error:
Traceback (most recent call last):
File "python-io.py", line 12, in <module>
csrftoken = session.cookies['csrftoken']
File "/home/bunni/.local/lib/python2.7/site-packages/requests/cookies.py", line 328, in __getitem__
return self._find_no_duplicates(name)
File "/home/bunni/.local/lib/python2.7/site-packages/requests/cookies.py", line 399, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"

Kindly advice.

My project involves logging in to a website and searching for specific content which will then be downloaded and parsed to be presented in a clean format. I started learning python about 2 weeks back to achieve this. But i am stuck. Can you please tell me where i am going wrong and what i can do about it?
Reply


Messages In This Thread
Requests login failure - by test - Sep-09-2018, 06:34 AM
RE: Requests login failure - by test - Sep-09-2018, 03:35 PM
RE: Requests login failure - by test - Sep-09-2018, 05:05 PM
RE: Requests login failure - by test - Sep-10-2018, 02:36 AM
RE: Requests login failure - by test - Sep-10-2018, 03:52 PM
RE: Requests login failure - by snippsat - Sep-10-2018, 06:01 PM
RE: Requests login failure - by test - Sep-11-2018, 01:43 AM
RE: Requests login failure - by test - Sep-13-2018, 02:20 AM
RE: Requests login failure - by test - Sep-13-2018, 03:35 AM
RE: Requests login failure - by snippsat - Sep-13-2018, 07:58 AM
RE: Requests login failure - by test - Sep-13-2018, 08:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  POST requests - different requests return the same response Default_001 3 1,950 Mar-10-2022, 11:26 PM
Last Post: Default_001
  How to perform a successful login(signin) through Requests in Python Kalet 1 2,349 Apr-24-2020, 01:44 AM
Last Post: Larz60+
  HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button Webtest 4 8,500 Aug-20-2019, 04:03 PM
Last Post: johnmina
  Using python requests module and BS4 to login on an Wordpress based website apollo 1 9,429 Feb-06-2018, 01:31 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020