Search code examples
pythonpycurl

typeError: unsetopt() is not supported for this option


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

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

def exploitdb_search(name):
    if len(name) != 0:

        query = str(name) + ' ' + 'site:https://www.exploit-db.com/'
        for data in search(query, num_results=1):
            if "https://www.exploit-db.com/exploits" in data:
                x = ContentCallback()
                c = pycurl.Curl()
                c.setopt(c.URL, '{}'.format(data))
                c.setopt(c.WRITEFUNCTION, x.content_callback(data))
                c.perform()
                c.close()
                print(t.content)

Solution

  • The value of the c.WRITEFUNCTION option should be a function. You're passing the result of calling the function, which is None because content_callback() doesn't return anything. Setting the option to None is interpreted as trying to unset the option, which isn't allowed for this option.

    You should take off the argument list to the function so that you pass a reference to the function.

    c.setopt(c.WRITEFUNCTION, x.content_callback)