Question

I'm trying to use CURL's CURLOPT_MAX_RECV_SPEED_LARGE option with the pycurl library. Here is my test code:

import sys
import pycurl


class Test:
    def __init__(self):
        self.contents = ''

    def body_callback(self, buf):
        self.contents = self.contents + buf

print >>sys.stderr, 'Testing', pycurl.version

t = Test()
c = pycurl.Curl()
c.setopt(c.URL, 'http://curl.haxx.se/dev/')
c.setopt(c.WRITEFUNCTION, t.body_callback)
c.setopt(c.CURLOPT_MAX_RECV_SPEED_LARGE, 1024)
c.perform()
c.close()

print t.contents

It produces an error; there does not seem to be a library constant defined for this option.

Traceback (most recent call last):
  File "/Users/nilayanand/Documents/workspace/photofeed/photofeed-desktop/test/curl.py", line 18, in <module>
    c.setopt(c.CURLOPT_MAX_RECV_SPEED_LARGE, 1024)
AttributeError: CURLOPT_MAX_RECV_SPEED_LARGE

How can I use the CURLOPT_MAX_RECV_SPEED_LARGE option with pycurl?

Was it helpful?

Solution

The attribute for the CURLOPT_MAX_RECV_SPEED_LARGE option doesn't include the CURLOPT_ prefix, it is just named MAX_RECV_SPEED_LARGE. Your code works if you correct the line that uses it to be:

c.setopt(c.MAX_RECV_SPEED_LARGE, 1024)

OTHER TIPS

I'm not sure this will work, but you can try to change this line

c.setopt(c.CURLOPT_MAX_RECV_SPEED_LARGE, 1024)

with this line

c.setopt(CURLOPT_MAX_RECV_SPEED_LARGE, 1024)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top