Logging in and using cookies in pycurl

Vance picture Vance · Feb 8, 2010 · Viewed 20.2k times · Source

I need to download a file that is on a password protected page. To get to the page manually I first have to authenticate via an ordinary login page. I want to use curl to fetch this page in script.
My script first logins. It appears to succeed--it returns a 200 from a PUT to /login. However, the fetch of the desired page fails, with a 500.

I am using a "cookie jar":

C.setopt(pycurl.COOKIEJAR, 'cookie.txt')

In verbose mode, I can see cookies being exchanged when I fetch the file I need. Now my question: Is there more to using a COOKIEJAR?

Answer

wds picture wds · Feb 25, 2010

I believe Curl will store the cookies but you need to use them explicitly. I've only ever used the command line interface for this though. Scanning the documentation I think you might want to try:

C.setopt(pycurl.COOKIEFILE, 'cookie.txt')

(before the second request)