Pycurl WRITEDATA WRITEFUNCTION collision/crash
Question: How do I turnoff WRITEFUNCTION and WRITEDATA?

Using pycurl I have a class call curlUtil. In it I have pageAsString (self,
URL) which returns a string.

To do this I setopt WRITEFUNCTION. Now in downloadFile (self, URL, fn,
overwrite=0) I do an open and self.c.Setopt (pycurl.WRITEFUNCTION, 0) which
cause problems. Int is not a valid argument.

I then assumed WRITEDATA would overwrite the value or there would be a
NOWRITEFUNCTION commend. NOWRITEFUNCTION didn't exist so I just used WRITEDATA
and Python crashed.

I wrote a quick func called reboot() which closes curl, opens it again, and
calls reset to put it in the default state. I call it in both pageAsString and
downloadFile and there is no problem at all. But, I don't want to reinitialize
curl. There might be some special options I set.

How do I turnoff WRITEFUNCTION and WRITEDATA?


Answer: using the writefunction, instead of turning it off would save you a lot off
trouble. you might want to rewrite your pageAsString by utilizing
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.
    

