Skip to main content

Hi Team,

 

I am using one Python script to read tables from PDF and storing that data into excel file.

When I tried the code in Python, it is working fine but When I am trying to integrate to in AA360 with execute function it is giving ‘bot error’.

Python Script:

import pdfplumber
import pandas as pd
 

# Get file paths from AA360 input arguments
def extract_tables_from_pdf(arg_path):
pdf_path = arg_pathg0]
excel_path = arg_pathg1]


    all_rows = _]

    with pdfplumber.open(pdf_path) as pdf:
        for page_number, page in enumerate(pdf.pages, start=1):
            tables = page.extract_tables()
            for table in tables:
                for row in table:
                    if any(cell.strip() if cell else "" for cell in row):
                        all_rows.append(row)

    # Create DataFrame without column headers
    df = pd.DataFrame(all_rows)
    print(df)
    df.to_excel(excel_path, index=False)
    #print(f"Data written to {excel_path}")
    #return df
   # Write to Excel
    df.to_excel(excel_path, index=False)
# Example usage

df_result = extract_tables_from_pdf(arg_path)
   

 

Can anyone please help me with this ?

Thanks!!

 

Hi ​@Anjali.K1,

 

There are two possibilities I am seeing.

  • If you have copy-pasted the given script directly from the AA workspace, then you need to check the indentation, as I can see issues with that in many places here. Correct them and test the script again.

or

  • This error can occur because you don’t have the pandas & pdfplumber libraries saved in the correct directory. When you create a Python script and run it directly, it downloads all dependencies locally to that project. In order to have AA run your script, all dependencies have to be saved globally. You can do this by opening the command prompt and run the command like pip install pandas pdfplumber on your user level, and you should be good to go. It should be stored in the location C:\program files\python38\lib\site-packages.

 

Hope any of these will help.


@Anjali.K1 The way you can know for sure what caused error is to look at the bot runner logs.

C:\ProgramData\AutomationAnywhere\BotRunner\Logs

Inside, you will find the actual error messages from Python, not just “bot error”. 


Hi ​@Anjali.K1,

 

There are two possibilities I am seeing.

  • If you have copy-pasted the given script directly from the AA workspace, then you need to check the indentation, as I can see issues with that in many places here. Correct them and test the script again.

or

  • This error can occur because you don’t have the pandas & pdfplumber libraries saved in the correct directory. When you create a Python script and run it directly, it downloads all dependencies locally to that project. In order to have AA run your script, all dependencies have to be saved globally. You can do this by opening the command prompt and run the command like pip install pandas pdfplumber on your user level, and you should be good to go. It should be stored in the location C:\program files\python38\lib\site-packages.

 

Hope any of these will help.

Hi Padmakumar 

  ​@Aaron.Gleason 

Thank you for reply.

I have checked the Pandas and Pdfplumber library and as ​@Aaron.Gleason  mentioned I checked the logs. I could not find anything that looks blocker here.

Can you please share code snippet for reference?

 

Thanks !!


Hi ​@Anjali.K1,

 

There are two possibilities I am seeing.

  • If you have copy-pasted the given script directly from the AA workspace, then you need to check the indentation, as I can see issues with that in many places here. Correct them and test the script again.

or

  • This error can occur because you don’t have the pandas & pdfplumber libraries saved in the correct directory. When you create a Python script and run it directly, it downloads all dependencies locally to that project. In order to have AA run your script, all dependencies have to be saved globally. You can do this by opening the command prompt and run the command like pip install pandas pdfplumber on your user level, and you should be good to go. It should be stored in the location C:\program files\python38\lib\site-packages.

 

Hope any of these will help.

Hi Padmakumar 

  ​@Aaron.Gleason 

Thank you for reply.

I have checked the Pandas and Pdfplumber library and as ​@Aaron.Gleason  mentioned I checked the logs. I could not find anything that looks blocker here.

Can you please share code snippet for reference?

 

Thanks !!

Have you checked the indentation and libraries availability as suggested? Because, I replicated the scenario on a new VM and I was able to execute the script (after slight modification) by following the recommended steps as per my previous commend.

 

The modification I did in the code was not only just correcting the indentation but added an extra logic to convert the pandas Dataframe into a JSON object which could be the issue in your case since any of my suggested fixes were not working for you.

 

Here is the Input & Output
 

 


I checked the logs. I could not find anything that looks blocker here.

@Anjali.K1 All errors in Python appear in the logs. It will tell you exactly what is wrong. Run the problematic bot, open the logs, look at the timestamp when you ran your bot, and you will find the exact error, which will point you directly to the solution.

@Padmakumar The indent thing is one of the reasons I really, really dislike Python.  🤣


I checked the logs. I could not find anything that looks blocker here.

@Anjali.K1 All errors in Python appear in the logs. It will tell you exactly what is wrong. Run the problematic bot, open the logs, look at the timestamp when you ran your bot, and you will find the exact error, which will point you directly to the solution.

@Padmakumar The indent thing is one of the reasons I really, really dislike Python.  🤣

Agreed. However, there is a way to add the auto-indentation feature in the VS though 🙂. Later we just need to copy-paste the script from it.


Indentation was only the issue and solved after corrections!!!

Thank You ​@Padmakumar  @Aaron.Gleason

 


Reply