http_client.py 文件源码

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

项目:StockScraper 作者: stovorov 项目源码 文件源码
def validate_response(called_method: Callable) -> Callable:
    """Decorator for HTTPClient validating received response for REST API methods.
    If status code from server is different than 200 raises HTTPError.

    :param called_method: requests methods - POST, GET, PUT, PATH, DELETE
    :return: response from server
    """
    def wrapper(method: Callable, endpoint: str, *args: List[Any], **kwargs: Dict[Any, Any]) -> Response:
        """Executes decorated function and checks status_code."""
        resp = called_method(method, endpoint, *args, **kwargs)
        if resp.status_code != 200:
            logging.error('HTTP Client returned status code %s for url %s', resp.status_code, resp.url)
            raise HTTPError('HTTP Client returned status code {0} for url {1}'.format(str(resp.status_code), resp.url))
        return resp
    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号