Skip to content

Meta Ads (Facebook/Instagram) MCP server for Claude, ChatGPT, Perplexity & Cursor — the Meta node of Pipeboard’s 5-platform family (+ Google, TikTok, Snap, Reddit). Hosted remote MCP, badged Meta Business Partner, free plan — no self-hosting required.

Enhance error handling in image downloading functions

Yves Junqueiradf870765c583
diff --git a/meta_ads_generated.py b/meta_ads_generated.py
index 75e2d73..456e707 100644
--- a/meta_ads_generated.py
+++ b/meta_ads_generated.py
@@ -98,6 +98,12 @@ async def download_image(url: str) -> Optional[bytes]:
response = await client.get(url, timeout=30.0)
response.raise_for_status()
return response.content
+ except httpx.HTTPStatusError as e:
+ print(f"HTTP Error: {e.response.status_code} - {str(e)}")
+ return None
+ except httpx.RequestError as e:
+ print(f"Request Error: {str(e)}")
+ return None
except Exception as e:
print(f"Error downloading image: {str(e)}")
return None
@@ -567,7 +573,8 @@ async def download_ad_creative_image(access_token: str, ad_id: str, output_path:
if not image_data:
return json.dumps({
"error": "Failed to download image",
- "image_url": image_url
+ "image_url": image_url,
+ "details": "Unable to download image. This might be due to authentication requirements, URL expiration, or content restrictions imposed by Meta. Consider accessing the image through the Meta Ads Manager interface."
}, indent=2)
# Store the image data in our global dictionary with the ad_id as key