我有一个 Python 脚本,可以调用 API 从 Zendesk 检索数据。(使用 Python 3.x)JSON 对象的结构如下:
{
"id": 35436,
"url": "https://company.zendesk.com/api/v2/tickets/35436.json",
"external_id": "ahg35h3jh",
"created_at": "2009-07-20T22:55:29Z",
"updated_at": "2011-05-05T10:38:52Z",
"type": "incident",
"subject": "Help, my printer is on fire!",
"raw_subject": "{{dc.printer_on_fire}}",
"description": "The fire is very colorful.",
"priority": "high",
"status": "open",
"recipient": "support@company.com",
"requester_id": 20978392,
"submitter_id": 76872,
"assignee_id": 235323,
"organization_id": 509974,
"group_id": 98738,
"collaborator_ids": [35334, 234],
"forum_topic_id": 72648221,
"problem_id": 9873764,
"has_incidents": false,
"due_at": null,
"tags": ["enterprise", "other_tag"],
"via": {
"channel": "web"
},
"custom_fields": [
{
"id": 27642,
"value": "745"
},
{
"id": 27648,
"value": "yes"
}
],
"satisfaction_rating": {
"id": 1234,
"score": "good",
"comment": "Great support!"
},
"sharing_agreement_ids": [84432]
}
我遇到问题的地方是"custom_fields"
具体的部分。我在每张票中都有一个特定的自定义字段,我需要它的值,我只想要那个特定的值。
为了省去 Python 代码的太多细节,我正在阅读下面每张票的每个值,并将其添加到输出变量中,然后再将该输出变量写入 .csv。这是发生破损的特定位置:
output += str(ticket['custom_fields'][id:23825198]).replace(',', '')+','
所有的替换废话都是为了确保因为它进入一个逗号分隔的文件,所以值中的任何逗号都被删除了。无论如何,这是我得到的错误:
output += str(ticket['custom_fields'][id:int(23825198)]).replace(',', '')+','
TypeError: slice indices must be integers or None or have an __index__ method
如您所见,我已经尝试了几种不同的变体来尝试解决问题,但尚未找到解决方法。我可以使用一些帮助!
谢谢...