8

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!

OneSolitaryNoob
  • 5,423
  • 3
  • 25
  • 43

1 Answers1

13

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()
perreal
  • 94,503
  • 21
  • 155
  • 181
  • I am doing the same: c = pycurl.Curl() fileOprurl = str(location) print("URL : ",fileOprurl) out="output_filename.txt" c.setopt(pycurl.HTTPHEADER,['x-api-key: %s' %str(api_key)]) c.setopt(pycurl.URL, fileOprurl) with open(out, "wb") as f: c.setopt(c.WRITEFUNCTION, f.write()) c.perform() c.close() f.close() But output file `output_filename.txt` is blank. Input file is not blank. – Salah Jun 12 '18 at 13:18