Question

My Python code is not working

  • 26 January 2022
  • 17 replies
  • 892 views

Badge +1

Hi,

I have a python code , while executing the python i am getting the correct output.

but at same time when i am calling the same python code through AA 360(V23), its stuck on execution steps. BoT is not retuning any error or output.


17 replies

Userlevel 5
Badge +12

Hi @Niraj Kumar​ ,

 

Can you share your code snippet?

Userlevel 5
Badge +11

might, white space, or entering new lines is will cause issue and please function names are defined correctly

Please check the below link for your reference

https://automationanywhere.wistia.com/medias/euyjjrfno4

fallow the solution and video mentioned by @Tamil Arasu10 (Customer)​ , even after it didnt resolved before running the bot please preload the python package in the packages section

Hi @Niraj Kumar​ have you solved the issue?I'm also facing same issue..even basic python code is also not working.It's stucks at the execution step.

Badge +1

@Abin Jilson​ yes,

 

Check your environment variable and put your code inside py script folder.

 

If your script is outside py script folder it won't return or execute the code.

Userlevel 1
Badge +4

Hi,

 

You can reach out to me, i can be able to help for the python code and integrate well with AA and A360.

Badge +3

Hi @patelmaulesh ,

 

Can you help me with below code.

It is working in VS studio but in AA it is throwing Bot error.

 

Userlevel 1
Badge +4

Hi Ashish,

 

Please share the code and the file that you are using in the code.

Also i found that f is missing from the code “from PyPDF2 import PdfReader, PdfWriter.

Badge +3

Hi @patelmaulesh 

 

Please find the code below.

 

def PDFCom():

from PyPDF2 import PdfReader,PdfWriter

try:

    Input= 'C:\\Users\\aitware\\Desktop\\Ashish Code\\133100.pdf'

    Output= 'C:\\Users\\aitware\\Desktop\\Ashish Code\\Out.pdf'

 

    reader = PdfReader(Input)

    writer = PdfWriter()

    count= len(reader.pages)

 

    for page in reader.pages:

        page.compress_content_streams()

        writer.add_page(page)

 

    with open(Output, "wb") as f:

        writer.write(f)

except Exception as e: print(e)

Userlevel 1
Badge +4

Hi AshishItWare,

 

If possible for you to share the pdf file that would be great as well.

 

I can test the code and will update you soon after getting the file.

 

Badge +3

Hi @patelmaulesh ,

 

I cannot share that file you can try with any pdf file.

This is the code to reduce the file size please try with any pdf file.

Thank you.

 

Userlevel 1
Badge +4

Hi AshishItWare,

 

I am checking with the code and while checking it also find some useful you tube link that can be useful to you.

 

 

Userlevel 1
Badge +4

Hi AshishITware,
 

Here is the code that help to compress the file size.

 

from pypdf import PdfReader, PdfWriter

reader = PdfReader("C:\\test\\InvoiceSimple.pdf")
writer = PdfWriter()

for page in reader.pages:
    page.compress_content_streams()  # This is CPU intensive!
    writer.add_page(page)

with open("C:\\test\\InvoiceSimple11.pdf", "wb") as f:
    writer.write(f)

Also go through the given below GitHub link for further details:-

https://github.com/py-pdf/pypdf/issues/1546

Badge +3

Hi @patelmaulesh ,

 

Thank you for your help.

 

Badge

While running python in AA Im getting error like this ,How can I solve this issue?

Badge +3

Check your code it maybe due to some formatting issue code don't work if we have extra space or misplaced any python line.

Did you install required Libraries in machine?

Badge

Hi Team,

I am getting infinity running of script for this simple statement, Please help me in this scenario.

i have used sample number as number input and python_Output as any type ouput varaible

 

Reply