# Invoke Python Method: Doesnt work

**URL:** <https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520>\
**Category:** Studio\
**Tags:** project-panel, question, studio, python, activities\
**Created:** [May 21, 2024, 4:10pm UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520 "2024-05-21T16:10:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheCode](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shecode/32/313434_2.png) [@sheCode](https://forum.uipath.com/u/sheCode)\
**Post date:** [May 21, 2024, 4:10pm UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/1 "2024-05-21T16:10:10Z")

</div>

Hi guys, I have a python script that executes a request to a webservice and receives the response back in xml format. When running the script through cmd, it works correctly.  
But when trying to run it through UiPath, I can’t. Below print and description of what I did:

1. In Python Scope I have the Library Path field and the Path field, I filled them with the following values:  
**Library Path:** “C:\Users\username\AppData\Local\Programs\Python\Python38\python38.dll”  
**Path:**"C:\Users\username\AppData\Local\Programs\Python\Python38"  

2. In Load Python Script, I filled in the path fields for the .py file and the output with a variable.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/3/f/63f757a1d63487258894e46de89e7090423a84a5.png)

1. Finally, I called the Invoke Python Method, calling my “_get\_boleto_” function from the script. **PS:** In my **InputParameters** I have the variable “numProcessamento” which is of type IEnumerable, and I needed to assign a value of type string within the InputParameter, so I created the string and passed it to “numProcessamento” using _New List( Of Object) From {numProcessamento\_str}_. And when I try to run it, the Invoke Python Method gives an error.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/3/2/c/32cb35c3ca19ca5644d7f0160ce698d5325d68a1.png)

Here is my .py script and my numProcessamento value for test is this “117009180”:

```auto
import sys
import requests
import json

def get_boleto(numero_processamento):
    soap_request = f"""
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://servicos.wsdetran.com.br">
       <soapenv:Header/>
       <soapenv:Body>
          <ser:consPagamentoDarUnico>
             <ser:in0>
             <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
             <TEnvio_ConsultPagamentoUnico xsi:schemaLocation="http://www.sefaz.al.gov.br Envio_ConsultaPagamento_v1.00.xsd" xmlns="http://www.sefaz.al.gov.br" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                 <DadosConsultaUnico> 
                   <numeroProcessamento>{numero_processamento}</numeroProcessamento>
                 </DadosConsultaUnico>
                 <tipoConsulta>N</tipoConsulta>
             </TEnvio_ConsultPagamentoUnico>
             ]]>
             </ser:in0>
          </ser:consPagamentoDarUnico>
       </soapenv:Body>
    </soapenv:Envelope>
    """

    headers = {
        'Content-Type': 'text/xml',
        'SOAPAction': 'http://servicos.wsdetran.com.br/consPagamentoDarUnico',
    }

    response = requests.post('http://emissaodarws.sefaz.al.gov.br:80/WSEmissaoDar/services', headers=headers, data=soap_request)

    if response.status_code == 200:
        print("Resposta da solicitação SOAP:")
        xml_result = response.content.decode('utf-8')
        #print(xml_result) # Print da resposta para depuração
        return xml_result
    else:
        print('Error making SOAP request')
        return {'error': 'Error making SOAP request'}
		
if __name__ == " __main__":
    if len(sys.argv) != 2:
        print("Uso: python get_boleto.py <numero_processamento>")
        sys.exit(1)

    numero_processamento = sys.argv[1] # Recebe o argumento externo
    resultado = get_boleto(numero_processamento)
    print(resultado)

```

Thanks!! 😃

---

<div class="post-metadata">

**Author:** ![Baskar\_Gurumoorthy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/baskar_gurumoorthy/32/220429_2.png) [@Baskar\_Gurumoorthy](https://forum.uipath.com/u/Baskar_Gurumoorthy)\
**Post date:** [May 21, 2024, 4:16pm UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/2 "2024-05-21T16:16:25Z")

</div>

Hi @sheCode

can you share the error screenshot how you getting the error.

---

<div class="post-metadata">

**Author:** ![sheCode](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shecode/32/313434_2.png) [@sheCode](https://forum.uipath.com/u/sheCode)\
**Post date:** [May 21, 2024, 4:45pm UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/3 "2024-05-21T16:45:19Z")

</div>

> [@sheCode](#):
>
> New List( Of Object) From {numProcessamento\_str}

yeah, look:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/2/1/4/214adf35b38f83a28509daab1b5a3bbbca77aadc.png)  
It’s a simple error with no description…

also, here is my .py script and my numProcessamento value for test is this “117009180”:

```auto
import sys
import requests
import json

def get_boleto(numero_processamento):
    soap_request = f"""
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://servicos.wsdetran.com.br">
       <soapenv:Header/>
       <soapenv:Body>
          <ser:consPagamentoDarUnico>
             <ser:in0>
             <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
             <TEnvio_ConsultPagamentoUnico xsi:schemaLocation="http://www.sefaz.al.gov.br Envio_ConsultaPagamento_v1.00.xsd" xmlns="http://www.sefaz.al.gov.br" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                 <DadosConsultaUnico> 
                   <numeroProcessamento>{numero_processamento}</numeroProcessamento>
                 </DadosConsultaUnico>
                 <tipoConsulta>N</tipoConsulta>
             </TEnvio_ConsultPagamentoUnico>
             ]]>
             </ser:in0>
          </ser:consPagamentoDarUnico>
       </soapenv:Body>
    </soapenv:Envelope>
    """

    headers = {
        'Content-Type': 'text/xml',
        'SOAPAction': 'http://servicos.wsdetran.com.br/consPagamentoDarUnico',
    }

    response = requests.post('http://emissaodarws.sefaz.al.gov.br:80/WSEmissaoDar/services', headers=headers, data=soap_request)

    if response.status_code == 200:
        print("Resposta da solicitação SOAP:")
        xml_result = response.content.decode('utf-8')
        #print(xml_result) # Print da resposta para depuração
        return xml_result
    else:
        print('Error making SOAP request')
        return {'error': 'Error making SOAP request'}
		
if __name__ == " __main__":
    if len(sys.argv) != 2:
        print("Uso: python get_boleto.py <numero_processamento>")
        sys.exit(1)

    numero_processamento = sys.argv[1] # Recebe o argumento externo
    resultado = get_boleto(numero_processamento)
    print(resultado)

```

---

<div class="post-metadata">

**Author:** ![Baskar\_Gurumoorthy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/baskar_gurumoorthy/32/220429_2.png) [@Baskar\_Gurumoorthy](https://forum.uipath.com/u/Baskar_Gurumoorthy)\
**Post date:** [May 21, 2024, 5:01pm UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/4 "2024-05-21T17:01:59Z")

</div>

can you try to surround your code with try except exception handler method in python.

starting code with try

at the end use except Exception as e:

the you can use print(e0 to print the exception.

atleast, you can come to know what kind of exception it is.

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [May 21, 2024, 5:59pm UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/5 "2024-05-21T17:59:40Z")

</div>

@sheCode,

You missed to pass Instance property of Invoke Python Method. It should be Result variable of Load Python Script

Instance = testPyResult

 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/9/e/79e372defffb7f2f375b52b37a675d101eeb672f.png)

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [May 22, 2024, 6:48am UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/6 "2024-05-22T06:48:47Z")

</div>

@sheCode

Try to open the error description from locals panel

cheers

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [May 25, 2024, 6:49am UTC](https://forum.uipath.com/t/invoke-python-method-doesnt-work/742520/7 "2024-05-25T06:49:24Z")

</div>

Closed on May 25, 2024, 6:49am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
