【问题标题】:typeError: unsetopt() is not supported for this optiontypeError:此选项不支持 unsetopt()
【发布时间】:2021-03-04 23:45:55
【问题描述】:
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)

【问题讨论】:

  • 你有什么问题?
  • 您在哪里定义t 中使用的print(t.content)
  • 我的问题是为什么当我使用 setopt 并拒绝在此处显示数据时它一直给我这个关于 unsetopt() 的错误 c.setopt(c.WRITEFUNCTION, x.content_callback(data))
  • 不,是 x,我没改,我的错

标签: python pycurl


【解决方案1】:

c.WRITEFUNCTION 选项的值应该是一个函数。您正在传递调用函数的结果,即None,因为content_callback() 不返回任何内容。将选项设置为None 被解释为试图取消设置该选项,该选项不允许这样做。

您应该取消函数的参数列表,以便传递对函数的引用。

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

【讨论】:

  • 请提出另一个问题。为什么它在 c.perform 也给我一个错误?
  • f.py:27:弃用警告:'#' 格式将需要 PY_SSIZE_T_CLEAN self.contents = self.contents + buf TypeError: can only concatenate str (not "bytes") to str Traceback (last recent call last): File "f.py", line 43, in exploitdb_search(emnt) File “f.py”,第 27 行,在exploitdb_search c.perform() pycurl.error: (23, 'Failed writing body (0 != 7323)')
  • content_callback() 的参数是一个字节串。您正在尝试将其连接到常规字符串。初始化self.contents = b''
  • 这里还有其他问题:stackoverflow.com/…
  • 类 ContentCallback: def __init__(self): self.contents = b'' def content_callback(self, buf): self.contents = self.contents + buf
猜你喜欢
  • 2016-09-27
  • 2021-03-24
  • 2020-02-03
  • 2015-07-02
  • 2021-10-25
  • 2018-06-10
  • 1970-01-01
  • 1970-01-01
  • 2018-06-01
相关资源
最近更新 更多