Why does Google App Engine Get Null Data?

I am a beginner in Google App Engine. I am trying to get the data of Klaviyo from Flask to Google Cloud Storage. When I run the code at my computer, everything runs very well, but after I push all my code in the Google Server, the data always gets null. In the code, I have had to calculate the values and I get integer and float data types. I tried to change schema, but the code does not work in the server. Then I convert it into string types, and the same problem occurs.

Please help me.

This is my code:

@app.route("/append_klaviyo_data")
def append_klaviyo_data():
    """Return a friendly HTTP greeting."""
    try:
        dt = data_handler()
        local_timezone = tzlocal.get_localzone()
        current_time = datetime.now(local_timezone)

        metrics = dt if isinstance(dt, list) and len(dt) == 12 else [""] * 12

        open_rate = metrics[0]
        click_rate = metrics[1]
        unsubscribed_rate = metrics[2]
        bounce_rate = metrics[3]
        delivery_rate = metrics[4]
        conversion_active_on_site_rate = metrics[5]
        conversion_viewed_product_rate = metrics[6]
        revenue_per_email = metrics[7]
        product_purchase_rate = metrics[8]
        average_order_value = metrics[9]
        subscriber_count = metrics[10]
        new_subscriber_count = metrics[11]

        date = current_time.strftime("%m-%d-%Y")
        results = {
            "date": [date, date],
            "title": ["Active on Site", "Viewed Product"],
            "open_rate": [open_rate, open_rate],
            "click_rate": [click_rate, click_rate],
            "unsubscribed_rate": [unsubscribed_rate, unsubscribed_rate],
            "bounce_rate": [bounce_rate, bounce_rate],
            "delivery_rate": [delivery_rate, delivery_rate],
            "conversion_rate": [
                conversion_active_on_site_rate,
                conversion_viewed_product_rate,
            ],
            "revenue_per_email": [revenue_per_email, revenue_per_email],
            "product_purchase_rate": [product_purchase_rate, product_purchase_rate],
            "average_order_value": [average_order_value, average_order_value],
            "new_subscribers": [
                new_subscriber_count,
                new_subscriber_count,
            ],
            "subscriber_counts": [
                subscriber_count,
                subscriber_count,
            ],
        }

        klaviyo_df = pd.DataFrame(results)

        client = bigquery.Client()

        print("size of dataframe = " + str(klaviyo_df.shape[0]))

        job_config = bigquery.LoadJobConfig(
            write_disposition="WRITE_APPEND"
        )

        job = client.load_table_from_dataframe(
            klaviyo_df, f"{project_id}.{dataset_id}.{table_name}", job_config=job_config
        )
        job.result()

        table = client.get_table(f"{project_id}.{dataset_id}.{table_name}")

        print(
            "Loaded {} rows and {} columns to {}".format(
                table.num_rows,
                len(table.schema),
                f"{project_id}.{dataset_id}.{table_name}",
            )
        )

        print(
            "Total records logged to BigQuery for Klaviyo =  "
            + str(klaviyo_df.shape[0])
        )
        return "Klaviyo Results Logged!"
    except Exception:
        ex_type, ex_value, ex_traceback = sys.exc_info()
        trace_back = traceback.extract_tb(ex_traceback)
        stack_trace = list()
        for trace in trace_back:
            stack_trace.append(
                "File : %s , Line : %d, Func.Name : %s, Message : %s, Exception type: %s, Exception message: %s"
                % (trace[0], trace[1], trace[2], trace[3], ex_type, ex_value)
            )
        return stack_trace
    finally:
        return metrics

def get_data() -> list:
    try:
        # Initialize variables
        metrics = {
            "delivered_email_count": 0,
            "bounced_email_count": 0,
            "spam_email_count": 0,
            "dropped_email_count": 0,
            "opened_email_count": 0,
            "clicked_email_count": 0,
            "unsubscribed_count": 0,
            "conversion_active_on_site_count": 0,
            "conversion_viewed_product_count": 0,
            "revenue_unique_count": 0,
            "total_revenue_count": 0,
            "total_order_count": 0,
            "delivered_email_unique_count": 0,
            "revenue_count": 0,
            "subscriber_count": 0,
            "new_subscriber_count": 0,
        }
        return [metrics[key] for key in metrics]



def data_handler():
    dt = get_data()
    if isinstance(dt, list) and len(dt) == 16:
        (
            delivered_email_count,
            bounced_email_count,
            spam_email_count,
            dropped_email_count,
            opened_email_count,
            clicked_email_count,
            unsubscribed_count,
            conversion_active_on_site_count,
            conversion_viewed_product_count,
            revenue_unique_count,
            total_revenue_count,
            total_order_count,
            delivered_email_unique_count,
            revenue_count,
            subscriber_count,
            new_subscriber_count,
        ) = dt
    else:
        # Handle the case where get_data() returns an error or unexpected result
        return dt

    total_recipients = (
        delivered_email_count
        + bounced_email_count
        + spam_email_count
        + dropped_email_count
    )
    open_rate = calculate_rate_metric(opened_email_count, delivered_email_count)
    click_rate = calculate_rate_metric(clicked_email_count, delivered_email_count)
    unsubscribed_rate = calculate_rate_metric(unsubscribed_count, total_recipients)
    bounce_rate = calculate_rate_metric(bounced_email_count, total_recipients)
    delivery_rate = calculate_rate_metric(delivered_email_count, total_recipients)
    conversion_active_on_site_rate = calculate_rate_metric(
        conversion_active_on_site_count, delivered_email_count
    )
    conversion_viewed_product_rate = calculate_rate_metric(
        conversion_viewed_product_count, delivered_email_count
    )
    revenue_per_email = (
        revenue_count / delivered_email_count if delivered_email_count != 0 else 0
    )
    product_purchase_rate = calculate_rate_metric(
        revenue_unique_count, delivered_email_unique_count
    )
    average_order_value = (
        total_revenue_count / total_order_count if total_order_count != 0 else 0
    )

    return [
        str(open_rate),
        str(click_rate),
        str(unsubscribed_rate),
        str(bounce_rate),
        str(delivery_rate),
        str(conversion_active_on_site_rate),
        str(conversion_viewed_product_rate),
        str(revenue_per_email),
        str(product_purchase_rate),
        str(average_order_value),
        str(subscriber_count),
        str(new_subscriber_count),
    ]

I am trying to upload the data from Klaviyo to Google Cloud Storage

New contributor

hoanglinh 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