# Programación en Python

## Cómo ejecutar código fuente de Python en Mavibot.ai

Para ejecutar un código fuente (extensión .py) se utiliza **code\_executor(URL, params)** donde

**URL** - la URL del código fuente (“<https://mavibot.ai/handler.py”> como ejemplo)

**params** - los parámetros que se necesitan para tu código (vienen como una línea JSON)

El valor devuelto es lo que retorna la función

Ejemplo:

![](https://lh5.googleusercontent.com/LS-DvyjzFkpV6FMf1xDu_lgBMle_VulqC6M2W1SIQdu_q7GzALODAfVzU4Xu41O-hk7_hRJvAxHL-GHzqWT5Gmn5WYntvr-KdmgxhBPqxxQ14l5Vs7cuPIkLEnisPcrFoCkLKiKfEky3VgOsDg)

{% hint style="success" %}
Si necesitas enviar solicitudes API desde una dirección IP rusa, te recomendamos usar el proxy de Salebot.

Ejemplo:

requests.get('<https://google.com>', proxies={'https': '[http://51.250.88.121:24532'}).text](https://docs.mavibot.ai/doc/es/caracteristicas-especiales/http:/51.250.88.121:24532'}\).text)
{% endhint %}

{% hint style="info" %}
`139.59.148.123` — ejecutor de código Python
{% endhint %}

**Requisitos para el código fuente:**

Tu código debe incluir una función handle(data) que acepte un parámetro que contenga un hash de los parámetros que especificaste en la configuración del bloque. La función debe devolver un valor que se pasará de vuelta al bot después de la ejecución. Para dividir el resultado en los parámetros del editor, devuélvelo como JSON.

Puedes ver un código de ejemplo aquí: <https://mavibot.ai/handler.py>

Puedes usar bibliotecas estándar, así como las que se enumeran a continuación:

requests \
logger \
gspread \
oauth2client \
numpy \
pyzbar \
fuzzywuzzy \
python-Levenshtein \
re \
urllib \
time \
json \
hmac \
hashlib \
beautifulsoup4 \
pandas \
base64 \
xmltodict \
mysql-connector-python \
zeep \
Google-api-python-client

### Resumen en video


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/doc/es/caracteristicas-especiales/programacion-en-python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
