test2 / modules /db_connection.py
AIdeaText's picture
Update modules/db_connection.py
b122c14 verified
raw
history blame
905 Bytes
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