Pycurl collision / crash WRITEDATA WRITEFUNCTION
How do I disable WRITEFUNCTION and WRITEDATA?
Using pycurl I have a calllUtil class. In it I have pageAsString (self, URL) which returns a string.
To do this, I set WRITEFUNCTION. Now in downloadFile (self, url, fn, overwrite = 0) I am doing open and self.c.Setopt (pycurl.WRITEFUNCTION, 0) which is causing problems. Int is not a valid argument.
Then I assumed that WRITEDATA would overwrite that value, or there would be a NOWRITEFUNCTION reward. NOWRITEFUNCTION doesn't exist, so I just used WRITEDATA and Python.
I wrote a quick func called reboot () that closes curl, reopens it, and calls reset to put it in its default state. I call this in both pageAsString and downloadFile and there is no problem. But I don't want to reinitialize the curl. There may be some special settings that I have set.
How do I disable WRITEFUNCTION and WRITEDATA?
by using the write function instead of disabling it, you have a hard time getting out of trouble. you might want to rewrite your pageAsString using WRITEFUNCTION ..
as an example:
from cStringIO import StringIO
c = pycurl.Curl()
buffer = StringIO()
c.setopt(pycurl.WRITEFUNCTION, buffer.write)
c.setopt(pycurl.URL, "http://example.com")
c.perform()
...
buffer.getvalue() # will return the data fetched.
source to share