1

Is there a retry option within Pycurl that I can set? I want to retry specifically on DNS resolution failures. I prefer not to roll my own retry, if possible.

curl --retry 3 "www.google.com"

Curl manpage has details about --retry option. But I don't see equivalent setopt in curl API documentation. Is that why there is no option within Pycurl for retry?

I looked at this SO question. Is that the only way to retry?

My current code is this:

    c = pycurl.Curl()

    b = six.BytesIO()
    c.setopt(pycurl.WRITEFUNCTION, b.write)
    c.setopt(pycurl.URL, "www.google.com")
    c.setopt(pycurl.POST, 1)
    c.setopt(pycurl.SSL_VERIFYHOST, 2)
    c.setopt(pycurl.SSL_VERIFYPEER, 1)
    c.setopt(pycurl.VERBOSE, 1)

    retries = 3

    while retries:
        try:
            c.perform()
        except as e:
            if 'Could not resolve' in str(e):
                retries -= 1
                continue
            # log exception e and exit here
Bhaskar
  • 2,549
  • 1
  • 21
  • 23

1 Answers1

1

pycurl does not provide a retry function.

For example, pycurl allows specifying data to be uploaded as a stream. If the upload fails, how would it be retried? Once data is read from the stream, it is no longer available.

If you are calling pycurl in such a way that the entire operation can be retried, you can retry it in your application.

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • That argument applies to `curl` as well, isn't it? As per this SO link, `curl` can be used to stream upload data: https://stackoverflow.com/a/31063794/630866 – Bhaskar May 20 '20 at 17:32
  • 1
    `curl` is a program. `libcurl` is the library. `curl`, being the program, can retry everything. `libcurl` cannot. Also keep in mind that php`s `libcurl` binding is called `curl`, this is different from `curl`-the-program. – D. SM May 20 '20 at 17:44