Timeout Error – Python script to update AGOL attributes

I’m trying to build a python script that will update attributes on feature layers on AGOL, end goal would be to have scheduled tasks to update the attributes nightly (without effecting geometry). My attribute update file is a csv with approximately 9000 row and about 6 columns. Every time I run the full csv file I run into a timeout error. I have reduced the file to 3 columns and still occasionally get the timeout error. I’m newer to python so I wouldn’t be surprised if this is a horribly inefficient way to complete this task.

import pandas as pd
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)

try:
    # Connect to ArcGIS Online
    gis = GIS('', 'UN', 'PW', expiration=9999)
    logging.info("Successfully connected to ArcGIS Online.")

    # Access the feature layer, use the polygon layer service url not feature layer
    layer_url = "layer url"
    feature_layer = FeatureLayer(layer_url)
    logging.info("Successfully accessed the feature layer.")

    # Read the CSV file
    df = pd.read_csv('updates.csv')
    updates_df = df.fillna(value=0)
    logging.info("Successfully read the CSV/xlsx file.")

    # Define the identifier field used in your CSV and feature layer
    csv_id_field = 'apprid'  # Identifier in CSV file
    layer_id_field = 'apprid'  # Corresponding field in feature layer

    # Query the feature layer to get all features
    query_result = feature_layer.query(where="1=1")#, out_fields="*")
    #logging.info(f"Full query result: {query_result}")
    logging.info(f"Query successful: {query_result}")

    # Check if 'features' key is present in the query result
    if not query_result.features:
        logging.error("Query result does not contain features. Check the layer URL and query parameters.")
        raise KeyError("Query result does not contain features")

    features = query_result.features
    logging.info(f"Successfully queried the feature layer. Number of features retrieved: {len(features)}")

    # Prepare updates based on the CSV file
    updates = []
    for feature in features:
        feature_id = feature.attributes[layer_id_field]
        update_row = updates_df[updates_df[csv_id_field] == feature_id]
        if not update_row.empty:
            updated_attributes = {"apprid": feature.attributes["apprid"]}
            for column in updates_df.columns:
                if column != csv_id_field:
                    updated_attributes[column] = update_row[column].values[0]
            updates.append({"attributes": updated_attributes})
        else:
            logging.warning(f"No update found for feature_id: {feature_id}")

    # Apply the attribute updates
    if updates:
        update_result = feature_layer.edit_features(updates=updates)
        logging.info(f"Updates Complete")
    else:
        logging.info("No updates to apply.")

except Exception as e:
    logging.error(f"An error occurred: {e}")

Saw something on another chain to add expiration = 9999 to my GIS connection. This didn’t seem to make a difference.

gis = GIS('', 'UN', 'PW', expiration=9999)

New contributor

eflam93 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật