Power Query报错:向仅需1个参数的函数传入2个参数求助
问题定位与修复
你的错误原因很明确:Web.Page函数仅接受1个参数,但你错误地传入了2个参数。
看代码里的这一行:
Source = Json.Document(Web.Page(Web.Contents(URL), [ Headers =[#"Authorization"="Basic ENCODE64PASSWORDS"]]))
你把本该传给Web.Contents的Headers参数,误放到了Web.Page的参数列表里。Web.Page的作用是解析HTML网页内容,而你要调用的API应该直接返回JSON数据,甚至不需要用Web.Page,直接对Web.Contents的结果做JSON解析即可。
修正后的代码
let Parameter = Excel.CurrentWorkbook(){[Name="Parameter"]}[Content], URL= Parameter[Column1]{0}, // 修正:Headers参数传给Web.Contents,去掉多余的Web.Page Source = Json.Document(Web.Contents(URL, [ Headers =[#"Authorization"="Basic ENCODE64PASSWORDS"]])), #"Converted to Table" = Record.ToTable(Source), Value = #"Converted to Table"{0}[Value], results = Value[results], #"Converted to Table1" = Table.FromList(results, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table1", "Column1", {"path", "upsertable"}, {"path", "upsertable"}), #"Filtered Rows" = Table.SelectRows(#"Expanded Column1", each ([upsertable] = true)), #"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"path", Order.Ascending}}) in #"Sorted Rows"
额外说明
如果你的API确实返回的是纯JSON数据,上面的修改就能解决问题。如果API返回的是包含JSON的网页(这种情况很少见),那你需要把Headers参数正确传给Web.Contents,再把结果传给Web.Page,写法应该是:
Source = Json.Document(Web.Page(Web.Contents(URL, [Headers =[#"Authorization"="Basic ENCODE64PASSWORDS"]])))
但绝大多数API直接返回JSON,所以第一种修正方式更合理。
内容的提问来源于stack exchange,提问作者user21070263
相关产品推荐
相关产品推荐

