Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 151545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:28:00+00:00 2026-05-11T09:28:00+00:00

How do i cancel a transfer in pycurl? i use to return -1 in

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:28:00+00:00Added an answer on May 11, 2026 at 9:28 am

    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:

    Return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it’ll signal an error to the library and it will abort the transfer and return CURLE_WRITE_ERROR.

    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:

     /* run callback */  arglist = Py_BuildValue('(s#)', ptr, total_size);  if (arglist == NULL)      goto verbose_error;  result = PyEval_CallObject(cb, arglist);  Py_DECREF(arglist);  if (result == NULL)      goto verbose_error;   /* handle result */  if (result == Py_None) {      ret = total_size;           /* None means success */  }  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;      }      ret = (size_t) obj_size;    /* success */  }  else if (PyLong_Check(result)) {       ... identical code for Long ...  }  else {      PyErr_SetString(ErrorObject, 'write callback must return int or None');      goto verbose_error;  } 

    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:

    /* If the previous block of data ended with CR and this block of data is    just a NL, then the length might be zero */ if(len) {   wrote = data->set.fwrite_func(ptr, 1, len, data->set.out); } else {   wrote = len; }  if(CURL_WRITEFUNC_PAUSE == wrote)   return pausewrite(data, type, ptr, len);  if(wrote != len) {   failf(data, 'Failed writing body (%d != %d)', (int)wrote, (int)len);   return CURLE_WRITE_ERROR; } 

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to cancel a keypress event in a textbox after pressing the return key.
I could only find the function confirm() that gives OK/Cancel buttons. Is there any
I'd like to have a program that runs in the background, listens for any
If I need to cancel some operation on a thread, when should I use
Dialog closes with Cancel result, no exceptions, as if you have pressed its close
I want to cancel this operation if the user selects a specific item because
Is there an easy way to cancel a curl_easy_perform from another thread?
Is there a way to cancel a pending operation (without disconnect) or set a
The basic idea behind a Cancel button is to enable closing your window with
This is inspired by the question OK-Cancel or Cancel-OK? . I remember reading somewhere

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.