You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python requests调用GridDB Cloud Web API遇403错误求助

GridDB Cloud REST API 403 Forbidden 问题排查

我尝试使用Python的requests库通过Web API连接GridDB Cloud,完成容器(表)创建、数据行插入及查询操作,但所有请求均返回403 Forbidden错误。

我已在脚本中替换了GridDB Cloud门户提供的实际端点与凭证信息,脚本代码如下:

import requests
import json

# Replace these with your actual GridDB Cloud details
BASE = "https://cloud5197.griddb.com:443/griddb/v2/clustername/dbs/dbname"  # replace with your endpoint
AUTH = ("userid", "password")  # replace with your credentials

r = requests.get(f"{BASE}/ping", auth=AUTH, timeout=10)
print("Status code:", r.status_code)
print("Response text:", r.text)

container_def = {
  "name": "iot_data",
  "columns": [
    {"name": "device_id", "type": "STRING"},
    {"name": "ts", "type": "TIMESTAMP"},
    {"name": "temp", "type": "DOUBLE"}
  ],
  "containerType": "COLLECTION",  # or TIMESERIES depending on plan
  "rowKey": ["device_id", "ts"]
}

r = requests.post(f"{BASE}/containers", auth=AUTH, json=container_def)
print("create container:", r.status_code, r.text)

# 2) Insert a row
row = {"device_id":"dev-01","ts":"2025-09-20T12:00:00Z","temp":23.5}
r = requests.post(f"{BASE}/containers/iot_data/rows", auth=AUTH, json=row)
print("insert row:", r.status_code, r.text)

# 3) Query rows (simple GET)
r = requests.get(f"{BASE}/containers/iot_data/rows", auth=AUTH)
print("rows:", r.status_code, r.text)

执行脚本后得到以下结果:

Status code: 403
Response text: <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

create container: 403 <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

insert row: 403 <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

rows: 403 <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

我的疑问:访问GridDB Cloud REST API是否需要额外配置(如IP白名单、SSL证书或代理)?我的端点格式是否正确?

环境信息:

  • OS: Windows 11
  • Python: 3.12
  • Library: requests 2.32
  • IDE: Visual Studio Code

内容的提问来源于stack exchange,提问作者Siraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 06:14:52