How do i cancel a transfer in pycurl? i use to return -1 in libcurl but pycurl doesnt seem to like that (‘pycurl.error: invalid return value for write callback -1 17’) return 0 doesnt work either, i get ‘error: (23, ‘Failed writing body’)’ . Also how do i do a try/except with pycurl? i dont see any examples online nor the pycurl examples from the site
Share
Example code would help here. Judging from the error message, and grepping for it in the source code, you’ve set up a write callback. This is configured, I think, by CURLOPT_WRITEFUNCTION, and the documentation for that says:
The pycurl wrapper code checks that the value is between 0 and the number passed to it. That’s why -1 failed, and why 0, triggers CURLE_WRITE_ERROR, raises the ‘failed writing body’ exception. The pycurl code is:
I don’t see any way in pycurl for this function to support another return value. There might be other ways, like setting up a progress callback, which does seem to allow aborts.
The relevant code in curl itself is:
so you can see that pycurl does not support returning the CURL_WRITEFUNC_PAUSE which curl itself allows. You can also see that curl has no way to support aborts through the write callback function. You will have to use something else.