Update app.py
Browse files
app.py
CHANGED
|
@@ -21,14 +21,15 @@ def download_file(task_id, filename, save_dir="attachments"):
|
|
| 21 |
save_path = os.path.join(save_dir, filename)
|
| 22 |
print(f"[DEBUG] Try download: url={url} save_path={save_path}")
|
| 23 |
try:
|
| 24 |
-
resp = requests.get(url, timeout=30)
|
| 25 |
print(f"[DEBUG] HTTP {resp.status_code} for {url}")
|
| 26 |
resp.raise_for_status()
|
| 27 |
-
|
|
|
|
| 28 |
print(f"Warning: Received HTML response, file might not exist: {filename}")
|
| 29 |
return None
|
| 30 |
-
|
| 31 |
-
|
| 32 |
f.write(resp.content)
|
| 33 |
print(f"Downloaded attachment for task {task_id} -> {save_path}")
|
| 34 |
return save_path
|
|
|
|
| 21 |
save_path = os.path.join(save_dir, filename)
|
| 22 |
print(f"[DEBUG] Try download: url={url} save_path={save_path}")
|
| 23 |
try:
|
| 24 |
+
resp = requests.get(url, timeout=30)
|
| 25 |
print(f"[DEBUG] HTTP {resp.status_code} for {url}")
|
| 26 |
resp.raise_for_status()
|
| 27 |
+
|
| 28 |
+
if resp.headers.get('content-type', '').startswith('text/html'):
|
| 29 |
print(f"Warning: Received HTML response, file might not exist: {filename}")
|
| 30 |
return None
|
| 31 |
+
|
| 32 |
+
with open(save_path, "wb") as f:
|
| 33 |
f.write(resp.content)
|
| 34 |
print(f"Downloaded attachment for task {task_id} -> {save_path}")
|
| 35 |
return save_path
|