def retry(times):
    def real_decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            retried_times = 0
            while True:
                try:
                    return func(*args, **kwargs)
                except Exception:
                    retried_times += 1
                    if retried_times > times:
                        raise
        return wrapper
return real_decorator
times如果是最多重试的次数(不算第一次的话),应该是这个代码。如果最后还是失败就会抛出原来的异常