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


Python httplib.SERVICE_UNAVAILABLE属性代码示例

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


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

示例1: _load_proxy_route

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def _load_proxy_route(self, route):
    locations = self._load_config_item('locations', route, required=True)
    sources = self._load_config_item('sources', route, required=True)
    proxy_sources = self._load_proxy_sources(sources)
    overflow_sources = self._load_config_item('overflow_sources',
                                              route,
                                              required=False,
                                              default=[])
    empty_endpoint_status_code = self._load_config_item(
        'empty_endpoint_status_code',
        route,
        required=False,
        default=httplib.SERVICE_UNAVAILABLE)
    proxy_overflow_sources = self._load_proxy_sources(overflow_sources)
    overflow_threshold_pct = self._load_config_item('overflow_threshold_pct',
                                                    route,
                                                    required=False)
    source_group_manager = SourceGroupManager(proxy_sources,
                                              proxy_overflow_sources,
                                              overflow_threshold_pct,
                                              self._signal_update_fn,)

    return ProxyRoute(
        locations, empty_endpoint_status_code, source_group_manager) 
开发者ID:tellapart,项目名称:aurproxy,代码行数:26,代码来源:backend.py

示例2: testRequestHasNotEnd

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def testRequestHasNotEnd(self):
    # Previous request's lease has timed out but the request has not.
    now = datetime.datetime.now()
    old = (now -
           datetime.timedelta(seconds=parameters._LEASE_DURATION_SEC + 1))
    self.shard_state.slice_start_time = old
    self.shard_state.slice_request_id = self.PREVIOUS_REQUEST_ID
    self.shard_state.put()
    handler, _ = self._create_handler()
    # Lease has ended.
    self.assertEqual(0,
                     handler._wait_time(self.shard_state,
                                        parameters._LEASE_DURATION_SEC),
                     lambda: now)
    # Logs API doesn't think the request has ended.
    self.assertFalse(handler._has_old_request_ended(self.shard_state))
    # Request has not timed out.
    self.assertTrue(handler._wait_time(
        self.shard_state,
        parameters._MAX_LEASE_DURATION_SEC,
        lambda: now))
    handler.post()
    self.assertEqual(httplib.SERVICE_UNAVAILABLE, handler.response.status) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:25,代码来源:handlers_test.py

示例3: testLeaseFreedOnSliceRetry

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def testLeaseFreedOnSliceRetry(self):
    # Reinitialize with faulty map function.
    self._init_job(__name__ + "." + test_handler_raise_exception.__name__)
    self._init_shard()
    handler, _ = self._create_handler()
    handler.post()
    self.assertEqual(httplib.SERVICE_UNAVAILABLE, handler.response.status)

    shard_state = model.ShardState.get_by_shard_id(self.shard_id)
    self.assertTrue(shard_state.active)
    # Slice stays the same.
    self.assertEquals(self.CURRENT_SLICE_ID, shard_state.slice_id)
    # Lease is freed.
    self.assertFalse(shard_state.slice_start_time)
    self.assertFalse(shard_state.slice_request_id)
    # Slice retry is increased.
    self.assertEqual(self.shard_state.slice_retries + 1,
                     shard_state.slice_retries) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:20,代码来源:handlers_test.py

示例4: retry_task

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def retry_task(self):
    """Ask taskqueue to retry this task.

    Even though raising an exception can cause a task retry, it
    will flood logs with highly visible ERROR logs. Handlers should uses
    this method to perform controlled task retries. Only raise exceptions
    for those deserve ERROR log entries.
    """
    self.response.set_status(httplib.SERVICE_UNAVAILABLE, "Retry task")
    self.response.clear() 
开发者ID:elsigh,项目名称:browserscope,代码行数:12,代码来源:base_handler.py

示例5: handle_one_request

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def handle_one_request(self):
    """Override."""
    self.raw_requestline = self.rfile.readline()
    if not self.raw_requestline:
      self.close_connection = 1
      return
    if not self.parse_request():
      return
    self.send_error(httplib.SERVICE_UNAVAILABLE, 'Busy.') 
开发者ID:elsigh,项目名称:browserscope,代码行数:11,代码来源:dev_appserver_multiprocess.py

示例6: testFutureTask

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def testFutureTask(self):
    handler, _ = self._create_handler(slice_id=self.CURRENT_SLICE_ID + 1)
    handler.post()
    self.assertEqual(httplib.SERVICE_UNAVAILABLE, handler.response.status) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:6,代码来源:handlers_test.py

示例7: testLeaseHasNotEnd

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def testLeaseHasNotEnd(self):
    self.shard_state.slice_start_time = datetime.datetime.now()
    self.shard_state.put()
    handler, _ = self._create_handler()

    with mock.patch("datetime.datetime", autospec=True) as dt:
      # One millisecons after.
      dt.now.return_value = (self.shard_state.slice_start_time +
                             datetime.timedelta(milliseconds=1))
      self.assertEqual(
          math.ceil(parameters._LEASE_DURATION_SEC),
          handler._wait_time(self.shard_state,
                             parameters._LEASE_DURATION_SEC))
      handler.post()
      self.assertEqual(httplib.SERVICE_UNAVAILABLE, handler.response.status) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:17,代码来源:handlers_test.py

示例8: testSliceAndShardRetries

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def testSliceAndShardRetries(self):
    """Test when a handler throws a non fatal exception."""
    self.init(__name__ + ".test_handler_raise_exception")
    TestEntity().put()

    # First time, the task gets retried.
    self._handle_request(expect_finalize=False)
    self.assertEqual(httplib.SERVICE_UNAVAILABLE, self.handler.response.status)
    self.verify_shard_state(
        model.ShardState.get_by_shard_id(self.shard_id),
        active=True,
        processed=0,
        slice_retries=1)

    # After the Nth attempt on slice, we retry the shard.
    shard_state = model.ShardState.get_by_shard_id(self.shard_id)
    shard_state.slice_retries = (
        parameters.config.TASK_MAX_DATA_PROCESSING_ATTEMPTS)
    shard_state.put()
    # TODO(user): fix
    self.handler.post()
    self.verify_shard_state(
        model.ShardState.get_by_shard_id(self.shard_id),
        active=True,
        result_status=None,
        processed=0,
        slice_retries=0,
        retries=1)

  # TODO(user): test MR jobs that only allow slice or shard retry when
  # it is configurable per job. 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:33,代码来源:handlers_test.py

示例9: testExceptionInHandler

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def testExceptionInHandler(self):
    """Test behavior when handler throws exception."""
    self.init(__name__ + ".test_handler_raise_exception")
    TestEntity().put()

    # Stub out context._set
    m = mox.Mox()
    m.StubOutWithMock(context.Context, "_set", use_mock_anything=True)

    # Record calls
    context.Context._set(mox.IsA(context.Context))
    context.Context._set(None)

    m.ReplayAll()
    try: # test, verify
      self.handler.post()
      self.assertEqual(httplib.SERVICE_UNAVAILABLE,
                       self.handler.response.status)

      # slice should be still active
      shard_state = model.ShardState.get_by_shard_id(self.shard_id)
      self.verify_shard_state(shard_state, processed=0, slice_retries=1)
      # mapper calls counter should not be incremented
      self.assertEquals(0, shard_state.counters_map.get(
          context.COUNTER_MAPPER_CALLS))

      # new task should not be spawned
      tasks = self.taskqueue.GetTasks("default")
      self.assertEquals(0, len(tasks))

      m.VerifyAll()
    finally:
      m.UnsetStubs() 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:35,代码来源:handlers_test.py

示例10: _post_request

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def _post_request(self, body, headers):
        retry_count = self.max_retries
        while True:
            logger.debug("POST %s %r %r", self.url.path, body, headers)
            try:
                self.connection.request('POST', self.url.path, body=body, headers=headers)
                response = self.connection.getresponse()
            except httplib.HTTPException as e:
                if retry_count > 0:
                    delay = math.exp(-retry_count)
                    logger.debug("HTTP protocol error, will retry in %s seconds...", delay, exc_info=True)
                    self.close()
                    self.connect()
                    time.sleep(delay)
                    retry_count -= 1
                    continue
                raise errors.InterfaceError('RPC request failed', cause=e)
            else:
                if response.status == httplib.SERVICE_UNAVAILABLE:
                    if retry_count > 0:
                        delay = math.exp(-retry_count)
                        logger.debug("Service unavailable, will retry in %s seconds...", delay, exc_info=True)
                        time.sleep(delay)
                        retry_count -= 1
                        continue
                return response 
开发者ID:lalinsky,项目名称:python-phoenixdb,代码行数:28,代码来源:client.py

示例11: handle_request

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def handle_request(self):
        parsed_request = self.parse_request(self.request.body)
        unpacked_requests = self.unpack_batch(parsed_request)
        context.main_logger.debug("Received an event batch of {num_requests} requests in batch handler {handler}"
                                  .format(num_requests=len(unpacked_requests),
                                          handler=self.__class__.__name__))

        if not context.request_processor.submit(self.create_request(unpacked_requests)):
            context.main_logger.warning("RequestProcessor queue size limit reached, sending back off response...")
            self.set_status(httplib.SERVICE_UNAVAILABLE)
        else:
            self.set_status(httplib.OK) 
开发者ID:Nordeus,项目名称:pushkin,代码行数:14,代码来源:batch.py

示例12: _do_sync_req

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def _do_sync_req(self, url, headers=None, params=None, data=None, timeout=None, method="GET"):
        url = "?".join([url, urlencode(params)]) if params else url
        all_headers = self._get_common_headers(params, data)
        if headers:
            all_headers.update(headers)
        logger.debug(
            "[do-sync-req] url:%s, headers:%s, params:%s, data:%s, timeout:%s" % (
                url, all_headers, params, data, timeout))
        tries = 0
        while True:
            try:
                server_info = self.get_server()
                if not server_info:
                    logger.error("[do-sync-req] can not get one server.")
                    raise NacosRequestException("Server is not available.")
                address, port = server_info
                server = ":".join([address, str(port)])
                server_url = "%s://%s" % ("http", server)
                if python_version_bellow("3"):
                    req = Request(url=server_url + url, data=urlencode(data).encode() if data else None,
                                  headers=all_headers)
                    req.get_method = lambda: method
                else:
                    req = Request(url=server_url + url, data=urlencode(data).encode() if data else None,
                                  headers=all_headers, method=method)

                # for python version compatibility
                if python_version_bellow("2.7.9"):
                    resp = urlopen(req, timeout=timeout)
                else:
                    resp = urlopen(req, timeout=timeout, context=None)
                logger.debug("[do-sync-req] info from server:%s" % server)
                return resp
            except HTTPError as e:
                if e.code in [HTTPStatus.INTERNAL_SERVER_ERROR, HTTPStatus.BAD_GATEWAY,
                              HTTPStatus.SERVICE_UNAVAILABLE]:
                    logger.warning("[do-sync-req] server:%s is not available for reason:%s" % (server, e.msg))
                else:
                    raise
            except socket.timeout:
                logger.warning("[do-sync-req] %s request timeout" % server)
            except URLError as e:
                logger.warning("[do-sync-req] %s connection error:%s" % (server, e.reason))

            tries += 1
            if tries >= len(self.server_list):
                logger.error("[do-sync-req] %s maybe down, no server is currently available" % server)
                raise NacosRequestException("All server are not available")
            self.change_server()
            logger.warning("[do-sync-req] %s maybe down, skip to next" % server) 
开发者ID:nacos-group,项目名称:nacos-sdk-python,代码行数:52,代码来源:client.py

示例13: _do_sync_req

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import SERVICE_UNAVAILABLE [as 别名]
def _do_sync_req(self, url, headers=None, params=None, data=None, timeout=None):
        url = "?".join([url, urlencode(params)]) if params else url
        all_headers = self._get_common_headers(params, data)
        if headers:
            all_headers.update(headers)
        logger.debug(
            "[do-sync-req] url:%s, headers:%s, params:%s, data:%s, timeout:%s" % (
                url, all_headers, params, data, timeout))
        tries = 0
        while True:
            try:
                server_info = self.get_server()
                if not server_info:
                    logger.error("[do-sync-req] can not get one server.")
                    raise ACMRequestException("Server is not available.")
                address, port, is_ip_address = server_info
                server = ":".join([address, str(port)])
                # if tls is enabled and server address is in ip, turn off verification

                server_url = "%s://%s" % ("https" if self.tls_enabled else "http", server)
                req = Request(url=server_url + url, data=urlencode(data).encode() if data else None,
                              headers=all_headers)

                # for python version compatibility
                if python_version_bellow("2.7.9"):
                    resp = urlopen(req, timeout=timeout)
                else:
                    if self.tls_enabled and is_ip_address:
                        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
                        context.check_hostname = False
                    else:
                        context = None
                    resp = urlopen(req, timeout=timeout, context=context)
                logger.debug("[do-sync-req] info from server:%s" % server)
                return resp
            except HTTPError as e:
                if e.code in [HTTPStatus.INTERNAL_SERVER_ERROR, HTTPStatus.BAD_GATEWAY,
                              HTTPStatus.SERVICE_UNAVAILABLE]:
                    logger.warning("[do-sync-req] server:%s is not available for reason:%s" % (server, e.msg))
                else:
                    raise
            except socket.timeout:
                logger.warning("[do-sync-req] %s request timeout" % server)
            except URLError as e:
                logger.warning("[do-sync-req] %s connection error:%s" % (server, e.reason))

            tries += 1
            if tries >= len(self.server_list):
                logger.error("[do-sync-req] %s maybe down, no server is currently available" % server)
                raise ACMRequestException("All server are not available")
            self.change_server()
            logger.warning("[do-sync-req] %s maybe down, skip to next" % server) 
开发者ID:alibaba,项目名称:acm-sdk-python,代码行数:54,代码来源:client.py


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