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