I'm trying to connect a Mage.ai pipeline to an endpoint of my development server (a microservice of my app). However, I barely have any knowledge on the topic and it's getting rough.
My app uses Vue and Flask and these are the steps I've followed until now:
I checked that the endpoint is valid.
curl -X POST http://localhost:4999/user/login -H "Content-Type: application/json" -d '{"username": "USERNAME", "password": "PASSWORD"}'Returns me an OK and a valid token.
Setted the app to run on 0.0.0.0, on both the microservice and the login endpoint. These are the lines of my login endpoint, for example:
if __name__ == '__main__': app.run( host='0.0.0.0', # host='127.0.0.1', port='4999', debug = True )WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on * Running on http://0.0.0.0:4999/ (Press CTRL+C to quit) * Restarting with statThis is the Vue message:
App running at: - Local: http://localhost:9528/ - Network: http://172.22.15.213:9528/Did a ping to establish a connection with that network address:
root@fcf10b9466d3:/home/src/pipelines/actualizarfirmas_test# ping 172.22.15.213 PING 172.22.15.213 (172.22.15.213) 56(84) bytes of data. ^C --- 172.22.15.213 ping statistics --- 52 packets transmitted, 0 received, 100% packet loss, time 52210ms
And that's it because I do not know what else to do.
This is my microservice important flask lines:
@app.route('/receive_results', methods=['POST'])
def receive_results():
data = request.json
print("Received results:", data)
status = data.get("status_received")
message = data.get("message_received")
return jsonify({
"status_received": status,
"message_received": message,
"details": "Conexión exitosa con la API."
})
if __name__ == '__main__':
app.run(
host='0.0.0.0',
# host='127.0.0.1',
port='5009',
# debug = True,
# threaded=False
)
This is the way I intended to connect with my microservice (I just wanted to send back a response of the status of the pipeline, fail, success and why):
import requests
def enviar_mensaje_amic(custom_args, res, msg, token):
custom_args['status_received'] = res
custom_args['message_received'] = msg
print(res)
print(token)
print(msg)
try:
result = {
"status_received": custom_args['status_received'],
"message_received": custom_args['message_received'],
"execution_details": "Custom results."
}
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
response = requests.post("http://172.22.15.213:5009/receive_results", json=result, headers=headers)
print(response.status_code)
print(response.json())
print("Datos recibidos:", response.status_code)
except Exception as e:
print(f"Error al enviar datos: {e}")
return
def amic_login(custom_args, config_data):
base_url = "http://172.22.15.213:4999"
login_endpoint = f"{base_url}/user/login"
userdata = custom_args.get('userdata', [])
user = userdata[0]
pwd = userdata[1]
payload = {
"username": user,
"password": pwd
}
try:
response = requests.post(login_endpoint, json=payload)
response_data = response.json()
if response.status_code != 200 or "token" not in response_data:
raise Exception(f"Autentificación fallida: {response_data.get('message', 'Incógnita...')}")
# MIRAR CUÁL ES LA ESTRUCTURA DEL JSON QUE SE DEVOLVERÍA (PRODUCIDO POR AMIC, ESTO ES UNA BASE GUÍA!)
return response_data['token']
except Exception as e:
raise Exception(f"Error inesperado durante la autentificación: {str(e)}")