【发布时间】:2019-07-30 00:03:28
【问题描述】:
我一直在尝试通过 Zendesk API 检索代理的回复时间数据。但是,每次我使用给定的指标“reply_time_in_minutes”时,我都会得到一个 KeyError。有人对我应该做什么有建议吗?
import requests
# Set the request parameters
url = 'https://domain.zendesk.com/api/v2/incremental/tickets.json?
start_time=1563230494'
user = 'email' + '/token'
pwd = 'token'
# Do the HTTP get request
response = requests.get(url, auth=(user, pwd))
# Check for HTTP codes other than 200
if response.status_code != 200:
print('Status:', response.status_code, 'Problem with the request.
Exiting.')
exit()
# Decode the JSON response into a dictionary and use the data
data = response.json()
ticket_list1 = data['tickets']
for ticket1 in ticket_list1:
print(ticket1['reply_time_in_minutes'])
【问题讨论】:
-
a 404 problem是什么意思?您只是尝试访问字典中的值,而不是发出 http 请求。发布带有完整回溯的错误消息(如果有)。 -
如果说 404 问题时出现 404 错误,则某些内容不可用,因为未找到 404。因此,您的网址可能有问题,或者用户不存在或类似情况。但是更多我们需要一个准确的错误信息
-
对不起,我写错了404问题。这是我在
print(ticket1['reply_time_in_minutes']) KeyError: ' reply_time_in_minutes'"
标签: python zendesk-api