# 错误 403：对于项目编号为 123456789 的消费者，服务 'cloudresourcemanager.googleapis.com' 的配额指标 '读取请求' 和限制 '每分钟每用户读取请求' 已超出配额。

- **ID:** `policy/gcp-resource-manager-quota-exceeded`
- **领域:** policy
- **类别:** resource_error
- **错误码:** `403`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Cloud Resource Manager API 有每分钟每用户的读取请求配额（默认 60/分钟），自动化脚本或 CI/CD 流水线在短时间内发出过多 API 调用导致超出该配额。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| GCP SDK 400.x | active | — | — |
| GCP SDK 410.x | active | — | — |
| GCP SDK 420.x | active | — | — |

## 解决方案

1. ```
   在代码中实现带抖动的指数退避，以在达到配额限制时减慢请求速率。
示例（Python）：
  import time
  import random
  def call_with_backoff(client, request, max_retries=5):
      for i in range(max_retries):
          try:
              return client.execute(request)
          except Exception as e:
              if 'Quota exceeded' in str(e):
                  sleep_time = (2 ** i) + random.uniform(0, 1)
                  time.sleep(sleep_time)
              else:
                  raise
      raise Exception("Max retries exceeded")
   ```
2. ```
   从 GCP 控制台请求增加 Cloud Resource Manager API 每分钟每用户读取请求的配额。这需要提交支持工单。
示例：
  转到 GCP 控制台 > IAM 和管理 > 配额 > 选择 'Cloud Resource Manager API' > '每分钟每用户读取请求' > 编辑 > 增加限制。
   ```
3. ```
   将多个读取请求批处理到单个 API 调用中，使用 'getIamPolicy' 或 'testIamPermissions' 方法处理多个资源，从而减少请求数量。
示例：
  # 使用 list 方法并设置较大的 page size 以减少调用次数
  request = cloudresourcemanager_v3.Projects().list(pageSize=100)
  while request:
      response = service.projects().list(body=request).execute()
      # 处理响应
      request = service.projects().list_next(request, response)
   ```

## 无效尝试

- **Retrying immediately after failure** — Simply retrying the request after a short delay may work temporarily but the quota will be exceeded again if the same rate of requests continues. (45% 失败率)
- **Creating a new service account** — Creating a new service account and re-running the script will still hit the same per-user quota limit if the script makes requests at the same rate. (60% 失败率)
- **Disabling and re-enabling the API** — Disabling and re-enabling the Cloud Resource Manager API does not reset the quota counter; the quota is based on per-user usage over time. (80% 失败率)
