首页 > 解决方案 > AdWords RateExceededError

问题描述

我正在构建一个帮助程序库来调用 AdWords (Google Ads) Keyword Planner API,并且在出现 RateExceededError 错误时遇到了麻烦。

我收到的具体错误消息如下。

GoogleAdsServerFault: RateExceededError <rateName=RATE_LIMIT, rateKey=null, rateScope=ACCOUNT, retryAfterSeconds=30, errorDetails="Quota check failed: QuotaInfo{quotaGroupId=v2-kwi-webapi-global, userId=global}"> Original AdsAPI trace for debugging [
com.google.ads.api.services.common.error.ApiException: RateExceededError <rateName=RATE_LIMIT, rateKey=null, rateScope=ACCOUNT, retryAfterSeconds=30, errorDetails="Quota check failed: QuotaInfo{quotaGroupId=v2-kwi-webapi-global, userId=global}">
Underlying ApiErrors are: 
    RateExceededError <rateName=RATE_LIMIT, rateKey=null, rateScope=ACCOUNT, retryAfterSeconds=30>

我目前正在使用以下设置来调用 API 并捕获错误,但偶尔仍会引发异常。有没有更好的方法来捕获这些错误并将异常记录为警告?

class AdwordsAPIException(Exception):
  pass

def call_adwords_api_client(self, selector):
  try:
    return _adwords_client.get(selector)
  except AdwordsAPIException:
    return None

提前谢谢了!

标签: pythongoogle-ads-api

解决方案


好吧,您已经创建了一个永远不会引发的自定义异常类,要跳过所有异常,试试这个

def call_adwords_api_client(self, selector):
  try:
    return _adwords_client.get(selector)
  except:
    return None

此外,api 建议等待 30 秒后再重试。祝你好运。


推荐阅读