python - 具有最大结果的 ZenPy 搜索调用
问题描述
我正在使用 ZenPy 在 ZenDesk 中搜索几张票:
open_tickets = zenpy_client.search(type='ticket', status=['new', 'open'], subject=subject, group=group_name, created_between=[two_weeks_ago_date, current_date])
问题是当我从这个 Search 调用中得到太多结果时(超过 1.000,因为它是 ZenDesk API 的新查询限制)。我得到以下异常:
<Invalid search: Requested response size was greater than Search Response Limits>
我正在尝试查看 ZenPy 文档,但找不到任何可用于将搜索调用限制为 10 页的参数(在本例中,1.000 条记录,因为我们每个请求获得 100 张票证)。
我最终在通话中进行了尝试,但我确信这不是最好的解决方案:
from zenpy.lib.exception import APIException
try:
open_tickets = zenpy_client.search(type='ticket', status=['new', 'open'], subject=subject, group=group_name, created_between=[two_weeks_ago_date, current_date])
except APIException as ex:
...
限制此搜索的最佳解决方案是什么?
我也知道我可以限制更多的日期,但是我们在一周的某一天创建了很多票,所以没有办法过滤更多,我只需要一直到限制。
参考:
- https://developer.zendesk.com/rest_api/docs/support/search
- https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits
谢谢!
解决方案
返回的生成器search
支持 Python 切片,因此以下代码会将结果拉取到 1000 条,并防止超出新限制:
ticket_generator = zenpy_client.search(type="ticket")
print(ticket_generator[:1000])
推荐阅读
- android - 单击 Gmail 后退按钮时将用户带回应用程序
- ios - Swift 异步打印顺序?
- dynamics-crm - 我们如何在 Dynamic 365 中使用区分大小写的数据执行高级搜索
- android - 如何在服务中获取资产?
- javascript - 删除javascript中url的第一段和最后一段
- django - Django:一次性在所有应用程序上运行 pylint
- ember.js - 当我刷新页面时,Ember-simple-auth 会话过期
- sql - BigQuery:使用 COUNT 作为 LIMIT
- java - 通过 HTTP 在 Java 上放置
- sql-server - 对索引字段执行 sp_prepexec 查询时性能不佳,为什么?