Search code examples
pythoncurlpycurl

Saving output to file using pycurl?


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!


Solution

  • 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()