Проблема с перебором, list object has no attribute

Помогите с проблемой, есть две функции: ping_complexes - пингует оборудование и добавляет статус в базу данных, вторая функция - check_stats, она должна перебрать все строки в базе данных, и те элементы, где Status = 'Online' - у них спарсить статистику ping_complexes работает хорошо, а вот на функции check_stats выдает ошибку: ??? 'list' object has no attribute 'Status'

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mangust.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
today = str(date.today())

class Mangustes(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    address = db.Column(db.Text, nullable=False)
    ip = db.Column(db.Text, nullable=False)
    serialNumber = db.Column(db.Text, nullable=False, primary_key=True)
    Status = db.Column(db.Integer)

    def __repr__(self):
        return '<Mangustes %r>' % self.id


def ping_complexes(row_size):
    try:
        records = Mangustes.query.limit(row_size).all()
        for record in records:
            if ping(record.ip) in (None, False):
                record.Status = 'Offline'
            else:
                record.Status = 'Online'
        db.session.commit()
    except Exception as e:
        print("???", e)

def check_stats(row_size):
    try:
        records = Mangustes.query.limit(row_size).all()
        for record in records(records.Status == 'Online'):
            url = 'http://' + record.ip + ':8200/api/v1/detection_storage/get_detections_stat?datetime_start=' + today + 'T00:00:00%2B05:00&datetime_end=' + today + 'T23:59:59%2B05:00'
            response = requests.get(url, timeout=5)
            forparse = response.json()
            all_detections = (forparse["statistic"]['all_detections'])
            if all_detections != 0:
               record.Status = 'Online'
            else:
               record.Status = 'NoStats'
               db.session.commit()
    except Exception as e:
        print("???", e)
ping_complexes(19)
check_stats(19)

Попробовал описать функцию так, но вылетает если нет ответа от сервера, если API недоступно, except ConnectionError не срабатывает, или срабатывает некорректно, ошибка:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.200.237.178', port=8200): Max retries exceeded with url: /api/v1/detection_storage/get_detections_stat?datetime_start=2022-08-23T00:00:00%2B05:00&datetime_end=2022-08-23T23:59:59%2B05:00 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001FFF8B01340>: Failed to establish a new connection: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение'))

def check_stats(row_size):
    records = Mangustes.query.limit(row_size).all()
    for record in records:
        try:
            if record.Status == "Online":
                url = 'http://' + record.ip + ':8200/api/v1/detection_storage/get_detections_stat?datetime_start=' + today + 'T00:00:00%2B05:00&datetime_end=' + today + 'T23:59:59%2B05:00'
                response = requests.get(url, timeout=5)
                forparse = response.json()
                all_detections = (forparse["statistic"]['all_detections'])
                if all_detections != 0:
                    record.Status = 'Online'
                else:
                    record.Status = 'NoStats'
            else:
                print(record.ip, ': Что-то оффлайн')
            db.session.commit()
        except ConnectionError:
            print(' Нет подключения к порту 8200')

check_stats(19)

Ответы (1 шт):

Автор решения: Vladislav Shvetsov

Получилось решить самому, получился такой код:

def check_stats(row_size):
    records = Mangustes.query.limit(row_size).all()
    for record in records:
        try:
            if record.Status == "Online":
                url = 'http://' + record.ip + ':8200/api/v1/detection_storage/get_detections_stat?datetime_start=' + today + 'T00:00:00%2B05:00&datetime_end=' + today + 'T23:59:59%2B05:00'
                response = requests.get(url, timeout=10)
                forparse = response.json()
                all_detections = (forparse["statistic"]['all_detections'])
                if all_detections != 0:
                    record.Status = 'Online'
                else:
                    record.Status = 'No driveways'
            else:
                print(record.ip, ': Offline')
        except Exception:
            record.Status='No connection 8200 port'
            print(record.ip, 'No connection 8200')
    db.session.commit()
→ Ссылка