util.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:cli 作者: riseml 项目源码 文件源码
def call_api(api_fn, not_found=None):
    try:
        return api_fn()
    except ApiException as e:
        if e.status == 0:
            raise e
        elif e.status == 401:
            handle_error("You are not authorized!")
        elif e.status == 403:
                handle_http_error(e.body, e.status)
        elif e.status == 404 and not_found:
            not_found()
        else:
            handle_http_error(e.body, e.status)
    except LocationValueError as e:
        handle_error("RiseML is not configured! Please run 'riseml user login' first!")
    except HTTPError as e:
        handle_error('Could not connect to API ({host}:{port}{url}) — {exc_type}'.format(
            host=e.pool.host,
            port=e.pool.port,
            url=e.url,
            exc_type=e.__class__.__name__
        ))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号