【问题标题】:Does Power Query support Accept-Encoding: gzip in Web.Contents()?Power Query 是否支持接受编码:Web.Contents() 中的 gzip?
【发布时间】:2015-11-26 07:45:13
【问题描述】:

这是一个在 blob 存储中未压缩的文件: https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFile.txt

这是相同的文件,但经过 gzip 压缩,并且 Content-Encoding blob 属性设置为 GZIP(如 here 所述): https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFileGzip.txt

第二个文件的大小只有一半,但是当我在网络浏览器中查看它们时,它们看起来都一样,因为网络浏览器可以解释响应中的标头“内容编码:gzip”

现在尝试使用 Power Query 中按预期工作的第一个文件:

let
    Source = Web.Contents("https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFile.txt"),
    #"Imported Text" = Table.FromColumns({Lines.FromBinary(Source,null,null,1252)})
in
    #"Imported Text"

但是,我似乎无法使用 Power Query 中的第二个文件。这会返回乱码,因为它从不解压缩 gzip 内容:

let
    Source = Web.Contents("https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFileGzip.txt", [Headers=[#"Accept-Encoding"="gzip"]]),
    #"Imported Text" = Table.FromColumns({Lines.FromBinary(Source,null,null,1252)})
in
    #"Imported Text"

有没有办法在 Power Query 中使用 gzip 后的 Web 内容?

更新:根据 Carl Walsh 在下面的回答,我在我的 blob 的属性上大写了 Content-Encoding: GZIP。我已经上传了一个带有 Content-Encoding: gzip (lowercase) 的新 blob,它可以工作:

let
    Source = Web.Contents("https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFileGzipLowercase.txt"),
    #"Imported Text" = Table.FromColumns({Lines.FromBinary(Source,null,null,1252)})
in
    #"Imported Text"

【问题讨论】:

  • 顺便说一句,Power Query 默认处理 gzip 和 deflate 编码。我会避免更改接受编码标头。

标签: powerbi powerquery


【解决方案1】:

正如 Lukasz 所指出的,在当前版本的 Power BI Desktop 2.28 中一切正常。 Power Query 版本 2.27 的公开下载已经发布,但在下个月的版本中它将开始工作。

问题在于 Azure Blob HTTP 响应包含 Content-Encoding 值“GZIP”,但 Web.Contents 仅在编码为小写“gzip”时才会自动解压缩。 (直到我们修复它!)


在旧版本的 Power Query 上,解决方法是使用 Binary.Decompress 手动解压缩 GZip:

let
    Source = Binary.Decompress(Web.Contents("https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFileGzip.txt", [Headers=[#"Accept-Encoding"="gzip"]]), Compression.GZip),
    #"Imported Text" = Table.FromColumns({Lines.FromBinary(Source,null,null,1252)})
in
    #"Imported Text"

但是一旦升级到 2.28 版,这将中断。(希望做出重大更改是正确的选择。)

【讨论】:

  • 哦,那是更好的消息。我控制了 Content-Encoding 属性,因此我将其更改为小写,即使没有指定 Accept-Encoding,它现在也可以在 Excel 2013 中使用。杰出的。谢谢卡尔。
【解决方案2】:

Greg,我在 Power BI 桌面的最新公共版本上进行了尝试,效果非常好。

根据格雷格的评论更新: 在 Excel 2013 中,将 Content-Encoding 属性设置为小写,它可以在不指定 Accept-Encoding 的情况下工作。 (感谢卡尔和格雷格!)

有效的查询(我认为这正是你写的:)

let
    Source = Web.Contents("https://gregsouthcentralstorage.blob.core.windows.net/publiccontainer/TestFileGzip.txt", [Headers=[#"Accept-Encoding"="gzip"]]),
    #"Imported Text" = Table.FromColumns({Lines.FromBinary(Source,null,null,1252)})
in
    #"Imported Text"

【讨论】:

  • 啊。我使用的是 Excel 2013 的最新版本。谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-02-27
  • 1970-01-01
  • 2014-10-09
  • 2011-02-16
  • 2020-01-27
  • 1970-01-01
  • 2016-12-28
  • 1970-01-01
相关资源
最近更新 更多