pycurl script can't login to website
Posted
by The Jug
on Stack Overflow
See other posts from Stack Overflow
or by The Jug
Published on 2010-06-16T21:21:22Z
Indexed on
2010/06/16
21:22 UTC
Read the original article
Hit count: 393
I'm currently trying to get a grasp on pycurl. I'm attempting to login to my own website. After logging into the site it should redirect to the main page. However when trying this script it just gets returned to the login page. What might I be doing wrong?
import pycurl
import urllib
import StringIO
import pycurl
pf = {'username' : 'user', 'password' : 'pass' }
fields = urllib.urlencode(pf)
pageContents = StringIO.StringIO()
p = pycurl.Curl()
p.setopt(pycurl.FOLLOWLOCATION, 1)
p.setopt(pycurl.COOKIEFILE, './cookie_test.txt')
p.setopt(pycurl.COOKIEJAR, './cookie_test.txt')
p.setopt(pycurl.POST, 1)
p.setopt(pycurl.POSTFIELDS, fields)
p.setopt(pycurl.WRITEFUNCTION, pageContents.write)
p.setopt(pycurl.URL, 'http://localhost')
p.perform()
pageContents.seek(0)
print pageContents.readlines()
© Stack Overflow or respective owner