import requests | |
import os | |
def call_azure_function(operation, data): | |
function_url = os.getenv('AZURE_FUNCTION_URL') | |
api_key = os.getenv('AZURE_FUNCTION_API_KEY') # Si está utilizando una clave de API | |
headers = { | |
'Content-Type': 'application/json', | |
'x-functions-key': api_key # Si está utilizando una clave de API | |
} | |
payload = { | |
'operation': operation, | |
'data': data | |
} | |
response = requests.post(function_url, json=payload, headers=headers) | |
if response.status_code == 200: | |
return response.json() | |
else: | |
raise Exception(f"Error calling Azure Function: {response.text}") |