Downnload CSV problem Julia - ArgumentError: Symbol name may not contain \0

Downnload CSV problem Julia - ArgumentError: Symbol name may not contain \0

我正在尝试使用下载和 CSV 从 Julia 中的 url 获取一个简单的 csv 文件,但没有成功。 这是我到目前为止所做的:

using Downloads, CSV
url = "https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv"
f = Downloads.download(url)
df = CSV.read(f, DataFrame)

但我收到以下错误:ArgumentError: 符号名称可能不包含 \0

我试过使用 normalizenames,但也没有成功:

f = Downloads.download(url)
df = CSV.File(f, normalizenames=true)

但随后我收到 无效的 UTF-8 字符串 作为错误消息。

当我简单地下载文件并使用 CSV.read 从我的 PC 获取它时,我没有收到任何错误。

服务器正在使用 Content-Encoding: gzip 提供该文件,即传输的数据是压缩的,客户端需要解压缩它。大家可以在命令行自己试试,curl默认不解压:

$ curl https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv                                                             [9:40:49]
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.

然而,如果您传递 --compressed 标志:

$ curl --compressed https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv
"time","Nile"
1871,1120
1872,1160
1873,963
[...]

Downloads.jl 使用 libcurl,我在 Downloads.jl 存储库中找不到太多关于压缩内容处理的提及。

要暂时解决此问题,您可以透明地升级到 CSV.jl、it handles gzipped CSV-files 的 v0.9.4。

如果无法更新,您可以手动使用 CodecZlib.jl:

using Downloads, CSV, DataFrames, CodecZlib
url = "https://r-data.pmagunia.com/system/files/datasets/dataset-85141.csv"
f = Downloads.download(url)
df = open(fh -> CSV.read(GzipDecompressorStream(fh), DataFrame), f)