File size: 905 Bytes
84ec5fc 28aefca 74ac7c0 84ec5fc 0d3433c 28aefca b122c14 84ec5fc 0d3433c 84ec5fc 28aefca b122c14 84ec5fc b122c14 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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')
print(f"Calling Azure Function: {function_url}")
print(f"Operation: {operation}")
print(f"Data: {data}")
headers = {
'Content-Type': 'application/json',
'x-functions-key': api_key
}
try:
response = requests.post(function_url, json={'operation': operation, 'data': data}, headers=headers)
print(f"Response status code: {response.status_code}")
print(f"Response content: {response.text}")
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Error calling Azure Function: {response.text}")
except requests.exceptions.RequestException as e:
print(f"Request exception: {str(e)}")
raise |