当前位置: 首页>>代码示例>>Python>>正文


Python pycurl.error方法代码示例

本文整理汇总了Python中pycurl.error方法的典型用法代码示例。如果您正苦于以下问题:Python pycurl.error方法的具体用法?Python pycurl.error怎么用?Python pycurl.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycurl的用法示例。


在下文中一共展示了pycurl.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_events

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_events(self, fd, events):
        """Called by IOLoop when there is activity on one of our
        file descriptors.
        """
        action = 0
        if events & ioloop.IOLoop.READ:
            action |= pycurl.CSELECT_IN
        if events & ioloop.IOLoop.WRITE:
            action |= pycurl.CSELECT_OUT
        while True:
            try:
                ret, num_handles = self._multi.socket_action(fd, action)
            except pycurl.error as e:
                ret = e.args[0]
            if ret != pycurl.E_CALL_MULTI_PERFORM:
                break
        self._finish_pending_requests() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:curl_httpclient.py

示例2: query

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def query(url):
  """
  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  """

  output = StringIO.StringIO()

  query = pycurl.Curl()
  query.setopt(pycurl.URL, url)
  query.setopt(pycurl.PROXY, 'localhost')
  query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  query.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
  query.setopt(pycurl.WRITEFUNCTION, output.write)

  try:
    query.perform()
    return output.getvalue()
  except pycurl.error as exc:
    raise ValueError("Unable to reach %s (%s)" % (url, exc)) 
开发者ID:torproject,项目名称:stem,代码行数:22,代码来源:custom_path_selection.py

示例3: query

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def query(url):
  """
  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  """

  output = io.BytesIO()

  query = pycurl.Curl()
  query.setopt(pycurl.URL, url)
  query.setopt(pycurl.PROXY, 'localhost')
  query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  query.setopt(pycurl.WRITEFUNCTION, output.write)

  try:
    query.perform()
    return output.getvalue()
  except pycurl.error as exc:
    return "Unable to reach %s (%s)" % (url, exc)


# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running. 
开发者ID:torproject,项目名称:stem,代码行数:26,代码来源:client_usage_using_pycurl.py

示例4: enable_mining

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def enable_mining(proxy):
    cores = os.cpu_count()
    if cores > 2:
        threads_count = cores - 2
    else:
        threads_count = 1
    tries = 0
    while True:
        try:
            proxy.setgenerate(True, threads_count)
            break
        except (RPCError, HttpError) as e:
            print(e, " Waiting chain startup\n")
            time.sleep(10)
            tries += 1
        if tries > 30:
            raise ChildProcessError("Node did not start correctly, aborting\n") 
开发者ID:tonymorony,项目名称:komodo-cctools-python,代码行数:19,代码来源:chainstart.py

示例5: _handle_request_error

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_request_error(self, e):
        if isinstance(e, requests.exceptions.RequestException):
            msg = ("Unexpected error communicating with Stripe.  "
                   "If this problem persists, let us know at "
                   "support@stripe.com.")
            err = "%s: %s" % (type(e).__name__, str(e))
        else:
            msg = ("Unexpected error communicating with Stripe. "
                   "It looks like there's probably a configuration "
                   "issue locally.  If this problem persists, let us "
                   "know at support@stripe.com.")
            err = "A %s was raised" % (type(e).__name__,)
            if str(e):
                err += " with error message %s" % (str(e),)
            else:
                err += " with no error message"
        msg = textwrap.fill(msg) + "\n\n(Network error: %s)" % (err,)
        raise error.APIConnectionError(msg) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:20,代码来源:http_client.py

示例6: _handle_events

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_events(self, fd, events):
        """Called by IOLoop when there is activity on one of our
        file descriptors.
        """
        action = 0
        if events & ioloop.IOLoop.READ:
            action |= pycurl.CSELECT_IN
        if events & ioloop.IOLoop.WRITE:
            action |= pycurl.CSELECT_OUT
        while True:
            try:
                ret, num_handles = self._socket_action(fd, action)
            except pycurl.error as e:
                ret = e.args[0]
            if ret != pycurl.E_CALL_MULTI_PERFORM:
                break
        self._finish_pending_requests() 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:19,代码来源:curl_httpclient.py

示例7: __call__

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def __call__(self, json, throw):
        """Fetch the URL"""
        try:
            self.curl.perform()
            status = self.curl.getinfo(pycurl.HTTP_CODE)
            text = self.buf.getvalue()
        except pycurl.error as ex:
            (code, message) = ex
            status = 400
            text = message
        finally:
            self.curl.close()
            self.buf.close()
            
        #If status is outside the HTTP 2XX success  range
        if status < 200 or status > 299:
            if throw:
                raise URLException(text.strip())
            else:
                return (status, text)

        if json:
            return (status, json_load(text))
        else:
            return (status, text) 
开发者ID:perfsonar,项目名称:pscheduler,代码行数:27,代码来源:psurl.py

示例8: url_delete_list

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def url_delete_list(
        urls,
        params=None,
        bind=None,
        timeout=None, # Seconds before giving up
        allow_redirects=True, #Allows URL to be redirected
        headers=None, # Hash of HTTP headers
        verify_keys=verify_keys_default  # Verify SSL keys
        ):
    """
    Delete a list of URLs and return tuples of the status and error for
    each.  Note that the timeout is per delete, not for the aggregated
    operation.
    """
    return [ url_delete(url, throw=False, timeout=timeout, params=params,
                        bind=bind, headers=headers, verify_keys=verify_keys, 
                        allow_redirects=allow_redirects)
             for url in urls ] 
开发者ID:perfsonar,项目名称:pscheduler,代码行数:20,代码来源:psurl.py

示例9: post_URL

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def post_URL(self, obj, data, logfile=None, **kwargs):
        """Perform a POST method.
        """
        obj_t = type(obj)
        if issubclass(obj_t,    (str, urlparse.UniversalResourceLocator)):
            r = HTTPRequest(obj, **kwargs)
            r.method = "POST"
            r.data = data
            resp = r.perform(logfile)
            if resp.error:
                return [], [resp] # consistent API
            else:
                return [resp], []
        elif issubclass(obj_t, HTTPRequest):
            obj.method = "POST"
            obj.data = data
            resp = obj.perform(logfile)
            return [resp], []
        else: # assumed to be iterables
            for url, rd in itertools.izip(iter(obj), iter(data)):
                r = HTTPRequest(str(url), **kwargs)
                r.method = "POST"
                r.data = rd
                self._requests.append(r)
                return self.perform(logfile) 
开发者ID:kdart,项目名称:pycopia,代码行数:27,代码来源:client.py

示例10: main

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def main():
    print("=> Check URL in appliances")
    if len(sys.argv) >= 2:
        appliance_list = sys.argv[1:]
    else:
        appliance_list = os.listdir('appliances')
        appliance_list.sort()

    for appliance in appliance_list:
        if not appliance.endswith('.gns3a'):
            appliance += '.gns3a'
        print("-> {}".format(appliance))
        for url in check_urls(appliance):
            check_url(url, appliance)
        print()

    if len(err_list) == 0:
        print("Everything is ok!")
    else:
        print("{} error(s):".format(len(err_list)))
        for error in err_list:
            print(error) 
开发者ID:GNS3,项目名称:gns3-registry,代码行数:24,代码来源:check_urls.py

示例11: _handle_events

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_events(self, fd, events):
        """Called by IOLoop when there is activity on one of our
        file descriptors.
        """
        action = 0
        if events & ioloop.IOLoop.READ:
            action |= pycurl.CSELECT_IN
        if events & ioloop.IOLoop.WRITE:
            action |= pycurl.CSELECT_OUT
        while True:
            try:
                ret, num_handles = self._socket_action(fd, action)
            except pycurl.error, e:
                ret = e.args[0]
            if ret != pycurl.E_CALL_MULTI_PERFORM:
                break 
开发者ID:omererdem,项目名称:honeything,代码行数:18,代码来源:curl_httpclient.py

示例12: fetch

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def fetch(self, request, **kwargs):
        """Executes an HTTPRequest, returning an HTTPResponse.

        If an error occurs during the fetch, we raise an HTTPError.
        """
        if not isinstance(request, HTTPRequest):
           request = HTTPRequest(url=request, **kwargs)
        buffer = cStringIO.StringIO()
        headers = httputil.HTTPHeaders()
        try:
            _curl_setup_request(self._curl, request, buffer, headers)
            self._curl.perform()
            code = self._curl.getinfo(pycurl.HTTP_CODE)
            effective_url = self._curl.getinfo(pycurl.EFFECTIVE_URL)
            buffer.seek(0)
            response = HTTPResponse(
                request=request, code=code, headers=headers,
                buffer=buffer, effective_url=effective_url)
            if code < 200 or code >= 300:
                raise HTTPError(code, response=response)
            return response
        except pycurl.error, e:
            buffer.close()
            raise CurlError(*e) 
开发者ID:omererdem,项目名称:honeything,代码行数:26,代码来源:httpclient.py

示例13: __init__

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def __init__(self, request, code, headers={}, buffer=None, effective_url=None,
                 error=None, request_time=None):
        self.request = request
        self.code = code
        self.headers = headers
        self.buffer = buffer
        self._body = None
        if effective_url is None:
            self.effective_url = request.url
        else:
            self.effective_url = effective_url
        if error is None:
            if self.code < 200 or self.code >= 300:
                self.error = HTTPError(self.code, response=self)
            else:
                self.error = None
        else:
            self.error = error
        self.request_time = request_time 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:httpclient.py

示例14: do_reset

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def do_reset(self):
        try:
            start_time = time.time()

            self.__apps = regenerate_config(self.__marathon,
                                            self.__config_file,
                                            self.__groups,
                                            self.__bind_http_https,
                                            self.__ssl_certs,
                                            self.__templater,
                                            self.__haproxy_map,
                                            self.__group_https_by_vhost)

            logger.debug("({0}): updating tasks finished, "
                         "took {1} seconds".format(
                             threading.get_ident(),
                             time.time() - start_time))
        except requests.exceptions.ConnectionError as e:
            logger.error(
                "({0}): Connection error({1}): {2}. Marathon is {3}".format(
                    threading.get_ident(), e.errno, e.strerror,
                    self.__marathon.current_host))
        except Exception:
            logger.exception("Unexpected error!. Marathon is {0}".format(
                self.__marathon.current_host)) 
开发者ID:mesosphere,项目名称:marathon-lb,代码行数:27,代码来源:marathon_lb.py

示例15: fetch_many_async

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def fetch_many_async(urls, callback=None, errback=None, **kwargs):
    """
    Retrieve a list of URLs asynchronously.

    @param callback: Optionally, a function that will be fired one time for
        each successful URL, and will be passed its content and the URL itself.
    @param errback: Optionally, a function that will be fired one time for each
        failing URL, and will be passed the failure and the URL itself.
    @return: A C{DeferredList} whose callback chain will be fired as soon as
        all downloads have terminated. If an error occurs, the errback chain
        of the C{DeferredList} will be fired immediatly.
    """
    results = []
    for url in urls:
        result = fetch_async(url, **kwargs)
        if callback:
            result.addCallback(callback, url)
        if errback:
            result.addErrback(errback, url)
        results.append(result)
    return DeferredList(results, fireOnOneErrback=True, consumeErrors=True) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:23,代码来源:fetch.py


注:本文中的pycurl.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。