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


Python exceptions.RetryError方法代码示例

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


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

示例1: request

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def request(self, url, *args, **kwargs):
        try:
            stream = HttpStream(url, *args, verbose=self.verbose, **kwargs)
            if kwargs.get('stream', False):
                return stream

            with stream as s:
                content = s.req.content
                return HttpResponse(s.status_code, s.headers, content)
        # Timeout will catch both ConnectTimout and ReadTimeout
        except (RetryError, Timeout) as ex:
            raise OsbsNetworkException(url, str(ex), '',
                                       cause=ex, traceback=sys.exc_info()[2])
        except HTTPError as ex:
            raise OsbsNetworkException(url, str(ex), ex.response.status_code,
                                       cause=ex, traceback=sys.exc_info()[2])
        except Exception as ex:
            raise OsbsException(cause=ex, traceback=sys.exc_info()[2]) 
开发者ID:containerbuildsystem,项目名称:osbs-client,代码行数:20,代码来源:http.py

示例2: vocabulary_delete

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def vocabulary_delete(url, datadict):
    if 'show' in url:
        return vocabulary_mockshow(url, datadict)
    if 'update' in url:
        resultdictcopy = copy.deepcopy(resultdict)
        resultdictcopy['tags'] = list()
        result = json.dumps(resultdictcopy)
        return MockResponse(200,
                            '{"success": true, "result": %s, "help": "http://test-data.humdata.org/api/3/action/help_show?name=vocabulary_update"}' % result)
    if 'delete' not in url:
        return MockResponse(404,
                            '{"success": false, "error": {"message": "TEST ERROR: Not delete", "__type": "TEST ERROR: Not Delete Error"}, "help": "http://test-data.humdata.org/api/3/action/help_show?name=vocabulary_delete"}')
    if datadict['id'] == '1731e7fc-ff62-4551-8a70-2a5878e1142b':
        if len(datadict['tags']) == 0:
            return MockResponse(200,
                                '{"success": true, "result": null, "help": "http://test-data.humdata.org/api/3/action/help_show?name=vocabulary_delete"}')
        else:
            raise RetryError(
                "HTTPSConnectionPool(host='test-data.humdata.org', port=443): Max retries exceeded with url: /api/action/vocabulary_delete (Caused by ResponseError('too many 500 error responses',))")

    return MockResponse(404,
                        '{"success": false, "error": {"message": "Not found", "__type": "Not Found Error"}, "help": "http://test-data.humdata.org/api/3/action/help_show?name=vocabulary_delete"}') 
开发者ID:OCHA-DAP,项目名称:hdx-python-api,代码行数:24,代码来源:test_vocabulary.py

示例3: post_with_retries

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def post_with_retries(url: str, data: dict, retries: int, backoff: float) -> int:
    """
    Make a POST request with retries.

    >>> post_with_retries('http://httpstat.us/503', {}, retries=1, backoff=0)
    500
    >>> post_with_retries('https://httpstat.us/200', {}, retries=1, backoff=0)
    200
    """
    retry_adapter = HTTPAdapter(max_retries=Retry(
        total=retries,
        backoff_factor=backoff,
        status_forcelist=[500, 502, 503, 504],
        method_whitelist=frozenset(['POST'])
    ))

    with Session() as session:
        session.mount('http://', retry_adapter)
        session.mount('https://', retry_adapter)

        try:
            response = session.post(url, data=data)
        except RetryError:
            return 500

        return response.status_code 
开发者ID:microsoft,项目名称:agogosml,代码行数:28,代码来源:http_request.py

示例4: get_manifest

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def get_manifest(self, image, version):
        saved_not_found = None
        media_type = get_manifest_media_type(version)
        try:
            response = query_registry(self._session, image, digest=None, version=version)
        except (HTTPError, RetryError) as ex:
            if ex.response is None:
                raise
            if ex.response.status_code == requests.codes.not_found:
                saved_not_found = ex
            # If the registry has a v2 manifest that can't be converted into a v1
            # manifest, the registry fails with status=400 (BAD_REQUEST), and an error code of
            # MANIFEST_INVALID. Note that if the registry has v2 manifest and
            # you ask for an OCI manifest, the registry will try to convert the
            # v2 manifest into a v1 manifest as the default type, so the same
            # thing occurs.
            if version != 'v2' and ex.response.status_code == requests.codes.bad_request:
                logger.warning('Unable to fetch digest for %s, got error %s',
                               media_type, ex.response.status_code)
                return None, saved_not_found
            # Returned if the manifest could not be retrieved for the given
            # media type
            elif (ex.response.status_code == requests.codes.not_found or
                  ex.response.status_code == requests.codes.not_acceptable):
                logger.debug("skipping version %s due to status code %s",
                             version, ex.response.status_code)
                return None, saved_not_found
            else:
                raise

        if not manifest_is_media_type(response, media_type):
            logger.warning("content does not match expected media type")
            return None, saved_not_found
        logger.debug("content matches expected media type")
        return response, saved_not_found 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:37,代码来源:util.py

示例5: _get_manifest_list

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def _get_manifest_list(self, image):
        """try to figure out manifest list"""
        if image in self.manifest_list_cache:
            return self.manifest_list_cache[image]

        reg_client = self._get_registry_client(image.registry)

        manifest_list = reg_client.get_manifest_list(image)
        if '@sha256:' in str(image) and not manifest_list:
            # we want to adjust the tag only for manifest list fetching
            image = image.copy()

            try:
                config_blob = reg_client.get_config_from_registry(image, image.tag)
            except (HTTPError, RetryError, Timeout) as ex:
                self.log.warning('Unable to fetch config for %s, got error %s',
                                 image, ex.response.status_code)
                raise RuntimeError('Unable to fetch config for base image')

            release = config_blob['config']['Labels']['release']
            version = config_blob['config']['Labels']['version']
            docker_tag = "%s-%s" % (version, release)
            image.tag = docker_tag

            manifest_list = reg_client.get_manifest_list(image)
        self.manifest_list_cache[image] = manifest_list
        return self.manifest_list_cache[image] 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:29,代码来源:pre_pull_base_image.py

示例6: get_json

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def get_json(self, url, **kwargs):
        response = None
        try:
            response = self.session.get(url, **kwargs)
            data = response.json()
            if type(data) is dict and data.get('error'):
                raise ServerResponsedError
            return data
        except ValueError as e:
            retries = kwargs.get('retries', 0)
            logger.error('when get <%d> %s, error %s (retry#%d)',
                         response.status_code, url, e, retries)
            return {} if retries <= self.max_retries else \
                self.get_json(url, retries=retries + 1)
        except ServerResponsedError:
            logger.error('when get <%d> %s, response: %s',
                         response.status_code, url, data)
            return {}
        except httplib.IncompleteRead as e:
            logger.error('when get %s, error %s; partial: %s',
                         url, e, e.partial)
            return {}  # or shall we return `e.partial` ?
        except RetryError as e:
            logger.error('when get %s, retry error occurs. %s', url, e)
            return {}
        except Exception as e:
            logger.error('error %s', e)
            return {} 
开发者ID:leVirve,项目名称:dcard-spider,代码行数:30,代码来源:utils.py

示例7: request

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import RetryError [as 别名]
def request(*args, **kwargs):

        url = kwargs.get('url') or \
            (args[0] if isinstance(args[0], str) else args[2])
        params = kwargs.get('params')

        if kwargs.get('stream'):
            return StreamResponse('./tests/data/' + 'sample.jpg')

        for i, bundle in enumerate(MockedRequest.mapping):

            regex, path = bundle

            if regex.search(url) is not None:
                json = JsonResponse('./tests/data/' + path)
                if (i == 1
                        and kwargs.get('params')
                        and kwargs.get('params').get('before')):
                    global post_metas_requests
                    post_metas_requests += 1
                    if post_metas_requests >= 50:  # cheating hacks Orz
                        return JsonResponse()
                elif i == 4:
                    json.comments_case = True
                    json.start = params.get('after', 0) if params else 0
                json.load_mockeddata()
                return json
        else:
            if kwargs.get('error') == 'ValueError':
                raise ValueError
            elif kwargs.get('error') == 'IncompleteRead':
                e = httplib.IncompleteRead(partial='some error here')
                raise e
            elif kwargs.get('error') == 'RetryError':
                raise RetryError
            elif kwargs.get('error') == 'Exception':
                raise Exception
            elif kwargs.get('resp_error'):
                return JsonResponse(error=kwargs.get('resp_error'))
            else:
                error_json = JsonResponse()
                error_json.result = {'error': 'Not found Ya'}
                error_json.status_code = 404
                return error_json 
开发者ID:leVirve,项目名称:dcard-spider,代码行数:46,代码来源:mocked.py


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