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

GridDB Cloud调用Web API创建Container时出现Invalid Container Definition错误

解决GridDB Cloud Web API创建Container时的Invalid Container Definition错误(400 Bad Request)

核心问题

你的代码里存在一个极易忽略的语法错误:container_name键使用了中文双引号(“container_name”),而JSON规范要求所有键名和字符串必须使用英文双引号("container_name")。这个错误直接导致GridDB API无法正确解析容器定义,触发Invalid Container Definition报错。

修正后的代码

把中文引号替换为英文引号后,代码就能正常工作:

import requests
import json

# Replace with your actual username and password
username = "xxxxxxx"
password = "xxxxxxx"

url = "http://127.0.0.1:8081/griddb/v2/mycluster/dbs/public/containers"
headers = {
    "Content-Type": "application/json"
}

container_definition = {
    "container_name": "employees",
    "container_type": "COLLECTION",
    "row_key": True,
    "columns": [
        {"name": "id", "type": "INTEGER"},
        {"name": "name", "type": "STRING"},
        {"name": "salary", "type": "DOUBLE"},
        {"name": "join_date", "type": "TIMESTAMP"}
    ]
}

# Use the auth parameter to send Basic Auth credentials
response = requests.post(url, headers=headers, json=container_definition, auth=(username, password))

if response.status_code == 201:
    print("Container created")
else:
    print(f"Error creating container: {response.text}")

额外检查项(如果修正后仍报错)

  • 确认container_type的值大小写正确,GridDB Web API支持COLLECTION和TIME_SERIES两种类型,必须全大写
  • row_key设为True时,需确保主键列(这里是id)的类型合法,INTEGER类型符合要求
  • 验证API URL中的集群名mycluster、数据库名public是否与你的GridDB配置一致
  • 检查用户名和密码的正确性,确保拥有创建容器的权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 21:03:14