Google Apps Script调用CryptoCompare API遇Address unavailable错误求助
Hey Matthias, sorry to hear you're stuck with this frustrating issue—especially since other crypto APIs are working fine for you. Let's walk through some likely fixes and debugging steps to get your script back up and running:
Possible Causes & Solutions
1. Google's Server IPs Are Blocked by CryptoCompare
Google Apps Script sends requests from Google's cloud IP ranges, which might have been temporarily flagged or blocked by CryptoCompare's firewall (this is a common issue with APIs that have strict rate limiting or anti-bot measures).
To work around this, try adding a custom user-agent header to mimic a browser request, which might help bypass the block:
const options = { method: "get", headers: { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" }, muteHttpExceptions: true // This lets you see full error details instead of just "Address unavailable" }; const response = UrlFetchApp.fetch("https://min-api.cryptocompare.com/data/blockchain/list", options); Logger.log(response.getContentText()); // Check the logs for specific error messages
2. Regional Restrictions on CryptoCompare's Endpoints
Some API providers restrict access based on the request's geographic origin. Google's servers might be located in a region that CryptoCompare is blocking right now.
- First, use the
muteHttpExceptionsflag above to capture the full response—you might get a clearer error like "access denied for your region". - If regional restrictions are confirmed, you could try integrating a proxy service (though this requires extra setup, such as using a third-party proxy API to forward your request).
3. Missing API Key in Request Headers (Even for "Public" Endpoints)
While /data/blockchain/list is listed as a public endpoint, some APIs require you to include your API key in headers even for public requests to track usage. Try adding your CryptoCompare API key to the request:
const options = { method: "get", headers: { "Authorization": "Apikey YOUR_CRYPTOCOMPARE_API_KEY", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" }, muteHttpExceptions: true }; const response = UrlFetchApp.fetch("https://min-api.cryptocompare.com/data/blockchain/list", options); Logger.log(response.getContentText());
4. Check CryptoCompare's Service Status
It's worth verifying if CryptoCompare is experiencing service outages or endpoint-specific issues. You can check their official status dashboard to see if other users are reporting similar problems.
Next Steps
Start with adding the muteHttpExceptions flag and custom headers to get detailed error logs—this will give you a clearer picture of exactly why the request is failing. From there, you can target the fix based on the error message you see.
内容的提问来源于stack exchange,提问作者Matthias Theiser

