Search code examples
pythoncurlpycurl

How to set persistent storage for curl cookies?


self.c.setopt(self.c.COOKIEFILE, 'cookie.txt')

However, the file is not created. What I want is to store and read cookies from file so they can be persistent after application restarts.

Does it have anything to do with COOKIEJAR option?


Solution

  • Yes. COOKIEFILE is the file to use as source of cookies for a session, COOKIEJAR is the file where cookies from the session should be stored.

    self.c.setopt(self.c.COOKIEFILE, 'cookie.txt')
    self.c.setopt(self.c.COOKIEJAR, 'cookie.txt')
    

    Notice that (depending on how your script is used) a relative path to the cookie file might give you unexpected results.