Excel 电源查询给出 DataSource.Error web.content 未能从 api url 获取内容 (404):未找到
Excel power query gives DataSource.Error web.content failed to get content from api url (404):Not Found
我的 excel 使用来自 api url 的数据,我 运行 每 10 分钟查询一次,但是如果 api 有很多流量和 returns 一个 404 错误,我收到一个弹出错误“DataSource.Error web.content 无法从 api url (404) 获取内容;未找到”并且整个传播 sheet 在我单击好之前无法正常工作,我需要做的是让查询继续尝试 api url 直到它获得数据 return 而不是抛出错误。
这是我 运行:
的查询
let
Source = Json.Document(Web.Contents("api url")),
#"Converted to Table" = Record.ToTable(Source),
#"Removed Top Rows" = Table.Skip(#"Converted to Table",9),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Removed Top Rows",6)
in
#"Removed Bottom Rows"
我尝试添加 MaunalStatusHandling,但它并没有解决问题,因为我不断收到错误消息。
我希望有人能告诉我解决这个问题的方法
提前感谢您的帮助
我找到了解决问题的方法,我会post以防其他人遇到类似问题
let
api_fnName = let
Value.WaitFor = (producer as function, interval as function, optional count as number) as any =>
let
list = List.Generate(
() => {0, null},
(state) => state{0} <> null and (count = null or state{0} < count),
(state) => if state{1} <> null
then {null, state{1}}
else {1 + state{0}, Function.InvokeAfter(() => producer(state{0}), interval(state{0}))},
(state) => state{1})
in
List.Last(list),
Web.ContentsCustomRetry = (url as text, optional options as record) => Value.WaitFor(
(i) =>
let
options2 = if options = null then [] else options,
options3 = if i=0 then options2 else options2 & [IsRetry=true],
result = Web.Contents(url, options3 & [ManualStatusHandling={500}]),
buffered = Binary.Buffer(result), /* avoid risk of double request */
status = if buffered = null then 0 else Value.Metadata(result)[Response.Status],
actualResult = if status = 500 then null else buffered
in
actualResult,
(i) => #duration(0, 0, 0, i*0.1))
in
Json.Document(Web.ContentsCustomRetry("api url")),
results = api_fnName[results],
results1 = results{0},
data = results1[data],
#"Converted to Table" = Record.ToTable(data),
#"Kept Range of Rows" = Table.Range(#"Converted to Table",4,1)
in
#"Kept Range of Rows"
我的 excel 使用来自 api url 的数据,我 运行 每 10 分钟查询一次,但是如果 api 有很多流量和 returns 一个 404 错误,我收到一个弹出错误“DataSource.Error web.content 无法从 api url (404) 获取内容;未找到”并且整个传播 sheet 在我单击好之前无法正常工作,我需要做的是让查询继续尝试 api url 直到它获得数据 return 而不是抛出错误。 这是我 运行:
的查询let
Source = Json.Document(Web.Contents("api url")),
#"Converted to Table" = Record.ToTable(Source),
#"Removed Top Rows" = Table.Skip(#"Converted to Table",9),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Removed Top Rows",6)
in
#"Removed Bottom Rows"
我尝试添加 MaunalStatusHandling,但它并没有解决问题,因为我不断收到错误消息。 我希望有人能告诉我解决这个问题的方法
提前感谢您的帮助
我找到了解决问题的方法,我会post以防其他人遇到类似问题
let
api_fnName = let
Value.WaitFor = (producer as function, interval as function, optional count as number) as any =>
let
list = List.Generate(
() => {0, null},
(state) => state{0} <> null and (count = null or state{0} < count),
(state) => if state{1} <> null
then {null, state{1}}
else {1 + state{0}, Function.InvokeAfter(() => producer(state{0}), interval(state{0}))},
(state) => state{1})
in
List.Last(list),
Web.ContentsCustomRetry = (url as text, optional options as record) => Value.WaitFor(
(i) =>
let
options2 = if options = null then [] else options,
options3 = if i=0 then options2 else options2 & [IsRetry=true],
result = Web.Contents(url, options3 & [ManualStatusHandling={500}]),
buffered = Binary.Buffer(result), /* avoid risk of double request */
status = if buffered = null then 0 else Value.Metadata(result)[Response.Status],
actualResult = if status = 500 then null else buffered
in
actualResult,
(i) => #duration(0, 0, 0, i*0.1))
in
Json.Document(Web.ContentsCustomRetry("api url")),
results = api_fnName[results],
results1 = results{0},
data = results1[data],
#"Converted to Table" = Record.ToTable(data),
#"Kept Range of Rows" = Table.Range(#"Converted to Table",4,1)
in
#"Kept Range of Rows"