Update modules/db_connection.py
Browse files- modules/db_connection.py +15 -10
modules/db_connection.py
CHANGED
|
@@ -5,19 +5,24 @@ def call_azure_function(operation, data):
|
|
| 5 |
function_url = os.getenv('AZURE_FUNCTION_URL')
|
| 6 |
api_key = os.getenv('AZURE_FUNCTION_API_KEY')
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
headers = {
|
| 9 |
'Content-Type': 'application/json',
|
| 10 |
'x-functions-key': api_key
|
| 11 |
}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
'operation': operation,
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
| 5 |
function_url = os.getenv('AZURE_FUNCTION_URL')
|
| 6 |
api_key = os.getenv('AZURE_FUNCTION_API_KEY')
|
| 7 |
|
| 8 |
+
print(f"Calling Azure Function: {function_url}")
|
| 9 |
+
print(f"Operation: {operation}")
|
| 10 |
+
print(f"Data: {data}")
|
| 11 |
+
|
| 12 |
headers = {
|
| 13 |
'Content-Type': 'application/json',
|
| 14 |
'x-functions-key': api_key
|
| 15 |
}
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
response = requests.post(function_url, json={'operation': operation, 'data': data}, headers=headers)
|
| 19 |
+
print(f"Response status code: {response.status_code}")
|
| 20 |
+
print(f"Response content: {response.text}")
|
| 21 |
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
return response.json()
|
| 24 |
+
else:
|
| 25 |
+
raise Exception(f"Error calling Azure Function: {response.text}")
|
| 26 |
+
except requests.exceptions.RequestException as e:
|
| 27 |
+
print(f"Request exception: {str(e)}")
|
| 28 |
+
raise
|