【发布时间】:2021-12-31 20:44:14
【问题描述】:
我正在尝试执行 API 调用来修补元素的名称和翻译。 translations 是一个数组,其中元素 name 和 alt_name 用唯一的 id 标识。
代码:
headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
headers["Content-Type"] = "application/json; charset=utf-8"
for row in reader:
data = '{"name": "' + row[1] + '", "alt_name": "' + row[2] + '", ' \
'"translations": [' + \
'{' + \
'"id": "661", "name": "' + row[1] + '", "alt_name": "' + row[2] + '"}, ' + \
'{' + \
'"id": "662", "name": "' + row[3] + '", "alt_name": "' + row[4] + \
'"}]}'
base_url = 'https://URL/path?&access_token=TOKEN'
resp = requests.patch(base_url, headers=headers, data=data)
除了内部翻译之外的所有内容都可以毫无问题地进行修改。我错过了什么明显的东西吗?
【问题讨论】:
标签: python arrays python-3.x api directus