def wrapper(*args, **kwargs): try: return function(*args, **kwargs) except HTTPStatusError as e: if e.response.status_code == 400: e_str = get_http_err_content(e) if "ALREADY_ARCHIVED" in e_str: return None raise
def wrapper(*args, **kwargs): try: return f(*args, **kwargs) except HTTPStatusError as e: if e.response.status_code == code: e_str = get_http_err_content(e) if message in e_str: return None raise
def wrapper(*args, **kwargs): try: return function(*args, **kwargs) except HTTPStatusError as e: if e.response.status_code == 400: e_str = get_http_err_content(e) if "SUBSCRIPTION_ALREADY_EXISTS" in e_str: return None if "Already pinned" in e_str: return None raise
def wrapper(*args, **kwargs): try: return function(*args, **kwargs) except HTTPStatusError as e: """ { "error": { "code": 400, "errors": [ { "domain": "global", "message": "URL_ALREADY_EXISTS", "reason": "badRequest" } ], "message": "URL_ALREADY_EXISTS" } } { "error": { "code": 400, "errors": [ { "domain": "global", "message": "Feeds are required", "reason": "badRequest" } ], "message": "Feeds are required" } } """ if e.response.status_code == 400: e_str = get_http_err_content(e) if "URL_ALREADY_EXISTS" in e_str: raise UrlAlreadyExistsError(e) if "Feeds are required" in e_str: raise FeedsRequiredError(e) raise
def main(): arg_parser, args = parse_args() if args.list_prune_filters: list_prune_filters() return if args.debug: setup_logger() if not (args.auth or args.api or args.config or args.token): arg_parser.print_help() return if args.config == LIST_CONFIGS: list_configs() return if args.proxy: with open(args.proxy) as fh: proxy_info = json.load(fh) else: proxy_info = None api_info, auth_info, user = load_config(args.api, args.auth, args.user, args.config) if args.email: token_client = LumAppsClient( args.customer_id, None, auth_info=auth_info, api_info=api_info, proxy_info=proxy_info, no_verify=args.no_verify, ) token_getter = token_client.get_token_getter(args.email) else: token_getter = None api = BaseClient( auth_info, api_info, user=user, token=args.token, token_getter=token_getter, prune=args.prune, proxy_info=proxy_info, no_verify=args.no_verify, ) if args.config and (args.auth or args.api): store_config(api_info, auth_info, args.config, args.user) if not args.endpoint: arg_parser.print_help() sys.exit("\nNo endpoint specified. Found these:\n" + api.get_endpoints_info(sorted(api.endpoints))) name_parts = tuple(p for p in args.endpoint if "=" not in p) if name_parts not in api.endpoints: sys.exit(api.get_matching_endpoints(name_parts)) if args.help: print(api.get_help(name_parts, args.debug)) return params = { p[0]: p[2] for p in (a.partition("=") for a in args.endpoint if "=" in a) } if args.body_file: with open(args.body_file) as fh: params["body"] = json.load(fh) elif "body" in params: params["body"] = json.loads(params["body"]) # elif not sys.stdin.isatty() and args.body: # s = args.body.read() # print('will loads this: {}'.format(s)) # params['body'] = json.loads(s) cast_params(name_parts, params, api.endpoints) try: response = api.get_call(*name_parts, **params) except (BadCallError, RequestError) as err: sys.exit(err) except HTTPStatusError as err: err_reason = get_http_err_content(err) if err_reason: sys.exit(err_reason) else: sys.exit(err) print(json.dumps(response, indent=4, sort_keys=True))
def test_get_http_err_content(): err = object() s1 = get_http_err_content(err) assert s1 == ""