["python","python-requests","pyquery"]
How can I "log in" to a website using Python's Requests module?

I am trying to post a request to log in to a website using the Requests module in Python, but it’s not really working. I'm new to this...so I can't figure out if I should make my Username and Password cookies or some type of HTTP authorization thing I found (??). from pyquery import PyQuery import requests url = 'http://www.locationary.com/home/index2.jsp' So now, I think I'm supposed to use post() and cookies.... ck = {'inUserName': 'USERNAME/EMAIL', 'inUserPass': 'PASSWORD'} r = requests.post(url, cookies=ck) content = r.text q = PyQuery(content) title = q("title").text() print title I have a feeling that I'm doing the cookies thing wrong...I don't know. If it doesn't log in correctly, the title of the home page should come out to "Locationary.com", and if it does, it should be "Home Page." What is the explanation for a few things about Requests and cookies? ...It still didn't really work yet. Okay...so this is what the home page HTML says before you log in: </td><td><img src="http://www.locationary.com/img/LocationaryImgs/icons/txt_email.gif"> </td> <td><input class="Data_Entry_Field_Login" type="text" name="inUserName" id="inUserName" size="25"></td> <td><img src="http://www.locationary.com/img/LocationaryImgs/icons/txt_password.gif"> </td> <td><input class="Data_Entry_Field_Login" type="password" name="inUserPass" id="inUserPass"></td> So I think I'm doing it right, but the output is still "Locationary.com" I want to be able to stay logged in for a long time and whenever I request a page under that domain, I want the content to show up as if I were logged in.
If the information you want is on the page you are directed to immediately after login... Let’s call your ck variable payload instead, like in the python-requests documentation: payload = {'inUserName': 'USERNAME/EMAIL', 'inUserPass': 'PASSWORD'} url = 'http://www.locationary.com/home/index2.jsp' requests.post(url, data=payload) Otherwise... See tigerFinch's answer.