本文介绍了Excel Power Query - 用于等待 API 速率限制的睡眠或等待命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Excel Power Query (PQ) 2016 中,是否有这样的功能可以在继续之前插入SLEEP 15 seconds"?不是暂停,而是睡眠功能.

In Excel Power Query (PQ) 2016, is there such a function that can insert a "SLEEP 15 seconds" before proceeding? Not a pause, but a sleep function.

问题:我在PQ中写了一个函数来查询:https://westus.api.cognitive.microsoft.com/text/analytics/v2.0.按照设计,该功能运行良好.

Problem:I wrote a function in PQ to query: https://westus.api.cognitive.microsoft.com/text/analytics/v2.0. That function works fine, as designed.

我有一个包含 10K 条推文的工作表,我想将这些推文传递给该函数.当我这样做时,它会完成大约 60 次,并且我在 PQ 中收到一条 ERROR 行.看看 Fiddler 是这样说的:

I have a worksheet with 10K tweets that I want to pass to that function. When I do, it gets to ~60 or so complete and I get an ERROR line in PQ. A look at Fiddler says this:

message=超出速率限制.请在 11 秒后重试.statusCode=429

我认为如果我在 PQ 函数中插入一个 SLEEP 5 秒(等效)命令,它不会这样做.

I think if I insert a SLEEP 5 second (equivalent) command into the PQ function, it won't do this.

帮助&谢谢.

推荐答案

你想要 Function.InvokeAfter

 Function.InvokeAfter(function as function, delay as duration) as any

这是一个例子:

= Function.InvokeAfter( () => 2 + 2, #duration(0,0,0,5))

等待 5 秒后返回 4.

Returns 4 after waiting 5 seconds.

要回答您尚未提出的问题,如果您要再次执行完全相同的 Web.Contents 调用,您可能需要使用

To answer a question you didn't ask yet, if you're going to execute the exact same Web.Contents call a second time, you may need to use the

[IsRetry = true]

Web.Contents 选项以表明您确实想要再次运行网络请求..

option of Web.Contents to indicate you actually want to run the web request again..

这篇关于Excel Power Query - 用于等待 API 速率限制的睡眠或等待命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:20