当前位置:  开发笔记 > 编程语言 > 正文

龙卷风curl_httpclient:类型错误:此选项不支持unsetopt()吗?

如何解决《龙卷风curl_httpclient:类型错误:此选项不支持unsetopt()吗?》经验,为你挑选了1个好方法。

任何机构都可以帮助我分析错误堆栈:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/tornado/web.py", line 1144, in _when_complete
    if result.result() is not None:
  File "/usr/local/lib/python2.7/site-packages/tornado/concurrent.py", line 129, in result
    raise_exc_info(self.__exc_info)
  File "/usr/local/lib/python2.7/site-packages/tornado/stack_context.py", line 302, in wrapped
    ret = fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 550, in inner
    self.set_result(key, result)
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 476, in set_result
    self.run()
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 505, in run
    yielded = self.gen.throw(*exc_info)
  File "get_image.py", line 53, in async_fetch
    yield _f
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 496, in run
    next = self.yield_point.get_result()
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 395, in get_result
    return self.runner.pop_result(self.key).result()
  File "/usr/local/lib/python2.7/site-packages/tornado/concurrent.py", line 129, in result
    raise_exc_info(self.__exc_info)
  File "/usr/local/lib/python2.7/site-packages/tornado/stack_context.py", line 302, in wrapped
    ret = fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 550, in inner
    self.set_result(key, result)
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 476, in set_result
    self.run()
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 505, in run
    yielded = self.gen.throw(*exc_info)
  File "get_image.py", line 60, in async_fetch
    yield _f
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 496, in run
    next = self.yield_point.get_result()
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 395, in get_result
    return self.runner.pop_result(self.key).result()
  File "/usr/local/lib/python2.7/site-packages/tornado/concurrent.py", line 129, in result
    raise_exc_info(self.__exc_info)
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 221, in wrapper
    runner.run()
  File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 507, in run
    yielded = self.gen.send(next)
  File "get_image.py", line 43, in async_fetch
    request_timeout=request_timeout)
  File "/usr/local/lib/python2.7/site-packages/tornado/httpclient.py", line 199, in fetch
    self.fetch_impl(request, handle_response)
  File "/usr/local/lib/python2.7/site-packages/tornado/curl_httpclient.py", line 95, in fetch_impl
    self._process_queue()
  File "/usr/local/lib/python2.7/site-packages/tornado/curl_httpclient.py", line 233, in _process_queue
    curl.info["headers"])
  File "/usr/local/lib/python2.7/site-packages/tornado/curl_httpclient.py", line 295, in _curl_setup_request
    curl.setopt(pycurl.URL, native_str(request.url))
TypeError: unsetopt() is not supported for this option

这是async_fetch函数:

@tornado.gen.coroutine
def async_fetch(self, ourl, callback, headers=None, connect_timeout=3, request_timeout=12, replace=False):
    assert callable(callback)
    if ourl not in FETCHING or replace:
        future = GlobalAsyncClient.fetch(ourl, headers=headers, connect_timeout=connect_timeout,
                                         request_timeout=request_timeout)
        FETCHING[ourl] = future
    else:
        future = FETCHING[ourl]
    try:
        response = yield future
    except Exception as exc:
        if isinstance(exc, HTTPError) and exc.response is not None:
            _f = callback(exc.response)
            if _f is not None:
                yield _f
        else:
            self.log_exception(*sys.exc_info())
            self.return_error(404, 10, "can't get original image")
    else:
        _f = callback(response)
        if _f is not None:
            yield _f
    finally:
        FETCHING.pop(ourl, None)

回调之一可能是这样的:

def get_image_size(self, response, dest_file, original_file, ourl=None, whole=False):
    if err_ourl(response.effective_url):
        self.return_error(404, 10, "no such image")

    callback = functools.partial(self.get_image_size, dest_file=dest_file, original_file=original_file, whole=True)

    if response.error:
        if response.error.code == 416:
            return self.async_fetch(ourl, callback, replace=True)
        self.return_error(404, 10, str(response.error))

    try:
        if getimagesize.format_fromstring(response.body) == 'WEBP':
            return self.async_fetch(ourl, callback, replace=True)
        # noinspection PyStringFormat
        result = '{"w":%d, "h":%d}' % getimagesize.fromfileobj(response.buffer)[1:]
    except IOError:
        self.return_error(500, 10, "read/write image error")
    except:
        self.log_exception(*sys.exc_info())
        self.return_error(400, 10, "can't recognise img")
    else:
        self.set_header("Content-Type", "application/json")
        self.success_return(result)

        safe_write(dest_file, result)

        if whole:
            safe_write(original_file, response.body)

这是一种情况:我curl_httpclient在龙卷风中使用,获取图像文件并获取大小。首先使用Range标头获取som字节,如果远程服务器不支持该字节,则尝试不使用进行重新下载Range,当图像为webp格式时,请下载整个文件。

fetch Future当相同的请求同时出现时,持有该对象以重用它。

它工作正常,但TypeError有时会出现。

我正在使用python 2.7,龙卷风3.1.1,pycurl 7.19.0,libcurl.x86_64 7.19.7-40.el6_6.4



1> Ben Darnell..:

这是来自pycurl的错误消息;它的意思是“ URL可能不为None”。该网址有时会因重试而丢失(例如,当您构建时functools.partial(self.get_image_size)

推荐阅读
ar_wen2402851455
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有