【问题标题】:Julia HTTP GET Headers not working as intendedJulia HTTP GET 标头未按预期工作
【发布时间】:2022-01-22 19:51:48
【问题描述】:

我想下载一个范围内的 grib2 文件数据,就像在这个 Python 笔记本中所做的那样: https://nbviewer.org/github/microsoft/AIforEarthDataSets/blob/main/data/noaa-hrrr.ipynb (见单元格 5)

我尝试了以下代码,但它似乎下载了整个 GRIB 文件而不是范围:

using HTTP
url = "https://noaahrrr.blob.core.windows.net/hrrr/hrrr.20210513/conus/hrrr.t12z.wrfsfcf01.grib2"
range_start = 38448330
range_end   = 39758083
    
grib2_bytes = HTTP.request("GET", url; headers = Dict("Range" => Dict("bytes" => [range_start; range_end]) ) );

# save bytes to file
io = open("variable.grib2", "w");
write(io, grib2_bytes); # I can see the file is too big (148 MB)
close(io)

# rest of the code is just to read the data
# The downloaded file subset is a valid GRIB2 file.
using GRIB
f = GribFile("variable.grib2")
msg = Message(f)

【问题讨论】:

    标签: http julia


    【解决方案1】:

    要模仿 python 代码,您应该使用string interpolation

    range_start = 38448330
    range_end   = 39758083
    
    headers = Dict(
        "Range" => "bytes=$(range_start)-$(range_end)"
    )
    

    【讨论】:

      猜你喜欢
      • 2018-04-24
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      • 2016-04-14
      相关资源
      最近更新 更多