Cloudflare KV API 批量 PUT - 错误 10012 - 无法将 KVPair 解组为中间结构

Cloudflare KV API Bulk PUT - Error 10012 - could not unmarshal KVPair into intermediate struct

正在向 Python 中的 CF Workers KV 批量写入 PUT,无法弄清楚这里出了什么问题。据我所知,我的 JSON 有效。

这是我遇到的错误

错误

{ "result": null, "success": false, "errors": [ { "code": 10012, "message": "could not parse array of key/value objects from request body: 'could not unmarshal KVPair into intermediate struct: 'json: cannot unmarshal object into Go struct field kvPairJSON.value of type string''" } ], "messages": [] }

有效负载

[{ “key”:“aals”, “value”:{ “sup”:{ “firo”:“aals”, “mean”:“aals”, “alpha”:[]}}}]

代码

response = requests.put(f"{CF_BASEURL}/bulk", headers=headers, data=json.dumps(payload))

任何想法表示赞赏。我确定这是一个 SMH 时刻...

这是一条无用的错误消息,对此深表歉意。 Workers KV 值是普通字节,如果需要,可以 在 Worker 中反序列化(例如解析为 JSON)。我想你想做的只是,

import json
payload = [{ "key": "aals", "value": json.dumps('{"sup": {"firo": "aals", "mean": "aals", "alpha": []}}')}]

以便您的值被编码为字符串。然后在你的 Worker 中你可以,

let jsonValue = KV_NAMESPACE.get("aals", "json");