[Python] Running a Flask python Function give me : 'str' object has no attribute 'copy'

Discussão em 'Python' iniciado por Stack, Julho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with a LLM project where i have a PDF file that is being processed with LamaIndexParse , when i upload the file the api for parsing works fine then the server print the error :

    INFO:processing:Stored 6 chunks for agent da829d70-54d2-4c04-b806-3940a7195bd1
    ERROR:processing:Error processing PDF: 'str' object has no attribute 'copy'
    ERROR:__main__:pDF processing failed for da829d70-54d2-4c04-b806-3940a7195bd1: 'str' object has no attribute 'copy'


    The script contain more than 500 line so i will provide a snipe of the code :

    try:
    # Parse PDF with LlamaParse
    parsed_docs = self.llamaparse.parse(pdf_path)
    if not parsed_docs:
    raise ValueError("LlamaParse could not parse the PDF.")

    documents = []
    doc_level_metadata = {}

    for i, doc in enumerate(parsed_docs):
    # Step 1: Extract text and raw metadata from LlamaParse
    if isinstance(doc, dict):
    text = doc.get('text', '')
    raw_metadata = doc.get('metadata', {})
    elif isinstance(doc, tuple):
    text = doc[0]
    raw_metadata = doc[1] if len(doc) > 1 else {}
    else:
    text = str(doc)
    raw_metadata = {}

    # Step 2: Ensure metadata is always a dict
    metadata = {}
    if isinstance(raw_metadata, dict):
    metadata = raw_metadata.copy()
    elif isinstance(raw_metadata, str):
    try:
    parsed = json.loads(raw_metadata)
    if isinstance(parsed, dict):
    metadata = parsed
    else:
    metadata = {}
    except Exception:
    metadata = {}


    i have tried to check if the copy method is applied on an STR type variable to ensure that it work put still no result.

    Continue reading...

Compartilhe esta Página