Saving output to file using pycurl?

OneSolitaryNoob picture OneSolitaryNoob · May 18, 2014 · Viewed 7.5k times · Source

I'm using pycurl to fetch a jpg from a server, how would I go about saving this to a file?

I can't see an option to do it.

Thanks!

Answer

perreal picture perreal · May 18, 2014

You need to write the file yourself, here is an example:

import pycurl
c = pycurl.Curl()
c.setopt(c.URL, 'http://my.server/a.jpg')
with open('o.jpg', 'w') as f:
    c.setopt(c.WRITEFUNCTION, f.write)
    c.perform()