[英]Python3: string indices must be integers
I'm following the Taboola documentation to the T in order to update a campaign with retargeting audience lists, but I get this error "string indices must be integers" and I don't know what is wrong.我正在遵循 Taboola 文档到 T 以更新具有重新定位受众列表的活动,但我收到此错误“字符串索引必须是整数”,我不知道出了什么问题。 I searched through the site but I can't find find a question with JSON request formatted like mine below.我搜索了该网站,但找不到与我的格式类似的 JSON 请求问题。
Thank you for your help,感谢您的帮助,
data = {
"collection:" [
"type": "INCLUDE" ,
"collection:" [
23950,
23951,
23949,
23954,
23953
]
]
}
#Create campaign
resp = requests.post(url="https://backstage.taboola.com/backstage/api/1.0/" + accountName + "/campaigns/" + campId + "/targeting/audience_segments", data=json.dumps(data), headers=headers)
Documentation (PDF - see last page): https://github.com/taboola/Backstage-API/raw/master/Backstage%20API%20-%20Targeting.pdf文档(PDF - 见最后一页): https : //github.com/taboola/Backstage-API/raw/master/Backstage%20API%20-%20Targeting.pdf
I can't find find a question with JSON request formatted like mine我找不到像我这样格式的 JSON 请求的问题
The problem isn't specific to how JSON is formatted;问题并不特定于 JSON 的格式; especially because the error is from Python interpreter, but not the json
module.特别是因为错误来自 Python 解释器,而不是来自json
模块。
It's how you typed it.这就是你打字的方式。
This is trying to index a string (which must be an integer)这是试图索引一个字符串(它必须是一个整数)
"collection:" [...]
What you need instead looks like a key-value pair你需要的看起来像一个键值对
"collection" : [...]
Your data is not formatted correcting as per API requirements:您的数据未按照 API 要求进行格式更正:
data = {
"collection": {
"type": "INCLUDE" ,
"collection": [
23950,
23951,
23949,
23954,
23953
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.