Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from flask import Flask, render_template, request, jsonify
|
2 |
import os
|
3 |
-
import base64
|
4 |
import requests
|
5 |
import logging
|
6 |
from requests.adapters import HTTPAdapter
|
@@ -24,12 +23,8 @@ def send_to_zapier(image_path):
|
|
24 |
logging.error("Zapier webhook URL not set.")
|
25 |
return {"error": "Zapier webhook URL not set. Please set the ZAPIER_WEBHOOK_URL environment variable."}
|
26 |
try:
|
27 |
-
with open(image_path, "rb") as f:
|
28 |
-
image_data = f.read()
|
29 |
-
encoded_image = base64.b64encode(image_data).decode('utf-8')
|
30 |
-
|
31 |
payload = {
|
32 |
-
'
|
33 |
'filename': os.path.basename(image_path),
|
34 |
'content_type': 'image/jpeg'
|
35 |
}
|
@@ -37,10 +32,10 @@ def send_to_zapier(image_path):
|
|
37 |
session = requests.Session()
|
38 |
retries = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504])
|
39 |
session.mount('https://', HTTPAdapter(max_retries=retries))
|
40 |
-
logging.debug(f"Sending image to Zapier webhook: {ZAPIER_WEBHOOK_URL}")
|
41 |
response = session.post(ZAPIER_WEBHOOK_URL, json=payload, timeout=10)
|
42 |
response.raise_for_status()
|
43 |
-
logging.debug("Image sent to Zapier successfully.")
|
44 |
return {"status": "success"}
|
45 |
except requests.exceptions.RequestException as e:
|
46 |
logging.error(f"Failed to send to Zapier: {str(e)}")
|
|
|
1 |
from flask import Flask, render_template, request, jsonify
|
2 |
import os
|
|
|
3 |
import requests
|
4 |
import logging
|
5 |
from requests.adapters import HTTPAdapter
|
|
|
23 |
logging.error("Zapier webhook URL not set.")
|
24 |
return {"error": "Zapier webhook URL not set. Please set the ZAPIER_WEBHOOK_URL environment variable."}
|
25 |
try:
|
|
|
|
|
|
|
|
|
26 |
payload = {
|
27 |
+
'image_url': request.url_root + image_path,
|
28 |
'filename': os.path.basename(image_path),
|
29 |
'content_type': 'image/jpeg'
|
30 |
}
|
|
|
32 |
session = requests.Session()
|
33 |
retries = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504])
|
34 |
session.mount('https://', HTTPAdapter(max_retries=retries))
|
35 |
+
logging.debug(f"Sending image URL to Zapier webhook: {ZAPIER_WEBHOOK_URL}")
|
36 |
response = session.post(ZAPIER_WEBHOOK_URL, json=payload, timeout=10)
|
37 |
response.raise_for_status()
|
38 |
+
logging.debug("Image URL sent to Zapier successfully.")
|
39 |
return {"status": "success"}
|
40 |
except requests.exceptions.RequestException as e:
|
41 |
logging.error(f"Failed to send to Zapier: {str(e)}")
|