Input variable into Label List causing error with string

This script works with the Label section hardcoded:

import oci
import pandas as pd

# Create a default config using DEFAULT profile in default location
config = oci.config.from_file()

# Initialize service client with default config file
data_labeling_service_dataplane_client = oci.data_labeling_service_dataplane.DataLabelingClient(config)

# Define the Excel file location
excel_file_path = r'C:SMALLFILEEXCEL.xlsx'

# Load the Excel file into a pandas DataFrame
df = pd.read_excel(excel_file_path, header=None)  # No header row

# Loop through each row in the DataFrame
for index, row in df.iterrows():
    # Ensure there are two columns (record_id and labels)
    if len(row) < 1:
        print(f"Skipping row due to insufficient data: {row}")
        continue

    # Get the record_id and strip any unwanted characters (spaces, newlines)
    record_id2 = row[0].strip()

    label_str = row[1].strip()

    # Print the cleaned record_id for debugging purposes
    print(f"Using record_id: {record_id2}")

    try:
        # Create annotation request for each record
        create_annotation_response = data_labeling_service_dataplane_client.create_annotation(
            create_annotation_details=oci.data_labeling_service_dataplane.models.CreateAnnotationDetails(
                record_id=record_id2,  # Use the cleaned record_id without quotes
                compartment_id="myid",  # Replace with your compartment_id
                entities=[
                    oci.data_labeling_service_dataplane.models.GenericEntity(
                        entity_type="GENERIC",
                        labels=[oci.data_labeling_service_dataplane.models.Label(label="macular_edema"),
                                oci.data_labeling_service_dataplane.models.Label(label="scar")]
                    )
                ],
                freeform_tags={'example_key_2': 'example_value_2'},
                defined_tags={'example_key_3': {'example_nested_key': 'example_nested_value'}}
            ),
            opc_retry_token="a12354123",
            opc_request_id="example_opc_request_id"
        )

        # Print the response for each annotation created
        print(create_annotation_response.data)

    except oci.exceptions.ServiceError as e:
        # Print the full error details for debugging
        print(f"ServiceError: {e.message}")
        print(f"Request ID: {e.request_id}")
        print(f"Status Code: {e.status}")
        print(f"Error Code: {e.code}")
        print(f"Using record_id: {record_id2}")

But when trying to update the Labels with the value from my Excel file like this:

type heimport oci
import pandas as pd

# Create a default config using DEFAULT profile in default location
config = oci.config.from_file()

# Initialize service client with default config file
data_labeling_service_dataplane_client = oci.data_labeling_service_dataplane.DataLabelingClient(config)

# Define the Excel file location
excel_file_path = r'C:SMALLFILEEXCEL.xlsx'

# Load the Excel file into a pandas DataFrame
df = pd.read_excel(excel_file_path, header=None)  # No header row

# Loop through each row in the DataFrame
for index, row in df.iterrows():
    # Ensure there are two columns (record_id and labels)
    if len(row) < 1:
        print(f"Skipping row due to insufficient data: {row}")
        continue

    # Get the record_id and strip any unwanted characters (spaces, newlines)
    record_id2 = row[0].strip()

    label_str = row[1].strip()

    # Print the cleaned record_id for debugging purposes
    print(f"Using record_id: {record_id2}")

    try:
        # Create annotation request for each record
        create_annotation_response = data_labeling_service_dataplane_client.create_annotation(
            create_annotation_details=oci.data_labeling_service_dataplane.models.CreateAnnotationDetails(
                record_id=record_id2,  # Use the cleaned record_id without quotes
                compartment_id="compartmentid",  # Replace with your compartment_id
                entities=[
                    oci.data_labeling_service_dataplane.models.GenericEntity(
                        entity_type="GENERIC",
                        labels=label_str
                    )
                ],
                freeform_tags={'example_key_2': 'example_value_2'},
                defined_tags={'example_key_3': {'example_nested_key': 'example_nested_value'}}
            ),
            opc_retry_token="a12354123",
            opc_request_id="example_opc_request_id"
        )

        # Print the response for each annotation created
        print(create_annotation_response.data)

    except oci.exceptions.ServiceError as e:
        # Print the full error details for debugging
        print(f"ServiceError: {e.message}")
        print(f"Request ID: {e.request_id}")
        print(f"Status Code: {e.status}")
        print(f"Error Code: {e.code}")
        print(f"Using record_id: {record_id2}")
re

I get the error:

raise TypeError('Field {} with value {} was expected to be of type {} but was of type {}'.format(field_name, str(obj), declared_type, type(obj).__name__))

TypeError: Field entities[*].labels with value oci.data_labeling_service_dataplane.models.Label(label=”scar”), oci.data_labeling_service_dataplane.models.Label(label=”nevus”), oci.data_labeling_service_dataplane.models.Label(label=”increased_cup_disc”)
was expected to be of type list[Label] but was of type str

Any idea how to get that list[Label] to work with a value from the Excel file? My Excel file has that entire text in one cell that it is pulling over. I can update the Excel file if needed.

I tried creating a list without using strings at all which did not work.

New contributor

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

1

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