views:

362

answers:

2

in C do return -1 when i want to cancel the download in either the header or the write function. In pycurl i get this error

pycurl.error: invalid return value for write callback -1 17

I dont know what the 17 means but what am i not doing correctly?

+3  A: 

from pycurl.c:

else if (PyInt_Check(result)) {
    long obj_size = PyInt_AsLong(result);
    if (obj_size < 0 || obj_size > total_size) {
        PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size);
        goto verbose_error;
    }

this would mean 17 is the total_size - is this possible ? and -1 (result) is what your callback is returning.

RSabet
does this mean i cant cancel a transfer in the header w/o getting a pycurl error printed to the console?
acidzombie24
Looks like its not possible. Marked as accepted (BTW i dont need this anymore)
acidzombie24
A: 
import pycurl
import StringIO

c = pycurl.Curl()
s = StringIO.StringIO()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.HEADER, True)
c.setopt(pycurl.NOBODY, True)
c.setopt(pycurl.WRITEFUNCTION, s.write)
c.perform()

print(s.getvalue())
Nekmo
I dont see a way to cancel the download once it has begone but i dont need this anymore.
acidzombie24