DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   pycurl cookies (http://www.daniweb.com/forums/thread165989.html)

krammer Jan 4th, 2009 11:24 am
pycurl cookies
 
My problem is that I do not see cookies being captured with this forum submission that I have setup. Does anyone know what I am doing wrong? Any help is appreciated, thanks.

def main():

  # Request post page
  dev_null = StringIO.StringIO()
  pycurlConnect = pycurl.Curl()
  pycurlConnect.setopt(pycurl.USERAGENT, USER_AGENT)
  pycurlConnect.setopt(pycurl.URL, LOGIN_URL)
  pycurlConnect.setopt(pycurl.REFERER, REFERER)
  pycurlConnect.setopt(pycurl.POSTFIELDS, POST_DATA)
  pycurlConnect.setopt(pycurl.HTTPHEADER, HEADERS)
  pycurlConnect.setopt(pycurl.WRITEFUNCTION, dev_null.write)
  pycurlConnect.setopt(pycurl.COOKIEFILE, 'cookies.txt')
  pycurlConnect.setopt(pycurl.COOKIEJAR, 'cookies.txt')
  pycurlConnect.setopt(pycurl.POST, 1)
  pycurlConnect.setopt(pycurl.VERBOSE, 1)
  pycurlConnect.setopt(pycurl.FOLLOWLOCATION, 1)
  pycurlConnect.perform()

  print pycurlConnect.getinfo(pycurl.HTTP_CODE), pycurlConnect.getinfo(pycurl.EFFECTIVE_URL)
  print pycurlConnect.getinfo(pycurl.INFO_COOKIELIST)

  # Close connections
  dev_null.close()
  pycurlConnect.close()

krammer Jan 4th, 2009 11:51 am
Re: pycurl cookies
 
Actually I think my problem might be because of my print function, I forgot python 3.0 uses the parenthesis...although I still should have seen the cookies in the pcap file that I captured, so maybe the new print function is not my issue.

sneekula Jan 6th, 2009 11:20 am
Re: pycurl cookies
 
Also, Python30 should give you an error if you use the print statement instead of the print function.

Do you find pycurl easier to use than the usual cookielib and urllib2 modules that come with Python?

krammer Jan 6th, 2009 1:26 pm
Re: pycurl cookies
 
I've read pycurl is faster...it seems pretty easy to me...except for the cookie part. I'm pretty new to python so I've never used cookielib or urllib2, but i've looked at some examples and pycurl seems easier.

krammer Jan 7th, 2009 9:02 am
Re: pycurl cookies
 
Do you know how to capture the cookies with cookielib and urllib2?


All times are GMT -4. The time now is 8:34 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC