當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。