【问题标题】:Azure storage REST Api call - Invalid Header x-ms-versionAzure 存储 REST Api 调用 - 标头 x-ms-version 无效
【发布时间】:2018-08-21 12:33:20
【问题描述】:

根据 question 的建议和 API 文档(例如 Blob service REST API),我在标题中指定了 x-ms-version。我的代码适用于 Azurite,并通过 Azure 进行身份验证,但返回一个

HTTP/1.1 400 The value for one of the HTTP headers is not in the correct format.

xml正文有更多细节:

<Error>
    <Code>InvalidHeaderValue</Code>
    <Message>The value for one of the HTTP headers is not in the correct format.
RequestId:d39d2cad-301e-009e-1546-3940de000000
Time:2018-08-21T11:58:14.2369850Z</Message>
   <HeaderName>x-ms-version</HeaderName>
   <HeaderValue>2017-01-19</HeaderValue>
</Error>

我的猜测不是格式,而是值。如何找到正确的值,甚至是我可以尝试一次运行一个的所有可能值的列表,或者是否有人知道这是一个误导性错误,我需要寻找其他地方?

在玩这个的同时,又会生成一个x-ms-version=2015-02-21

HTTP/1.1 400 One of the request inputs is out of range.

这是请求:

 -> GET /mike-ecu-test?restype=container&comp=list HTTP/1.1
 -> Host: mikeecutest.blob.core.windows.net
 -> User-Agent: libcurl/7.54.0 r-curl/3.1 httr/1.3.1
 -> Accept-Encoding: gzip, deflate
 -> Accept: application/json, text/xml, application/xml, */*
 -> Authorization: SharedKey mikeecutest/mike-ecu-test:9j5XodD9OIslzMnzHXiU7c76EpOXFi5jeQITbHk/Y8g=
 -> x-ms-date: Wed, 22 Aug 2018 01:35:06 GMT
 -> x-ms-version: 2018-03-28

这是生成它的 r 代码,代码的功劳是这个 question 的答案 4

library("httr")
azureout <- function(){
    url <- "http://mikeecutest.blob.core.windows.net/mike-ecu-test?restype=container&comp=list"
    sak <- "dfgwhsfhsfg.....hjdkfgs==" 

    requestdate<-format(Sys.time(),"%a, %d %b %Y %H:%M:%S %Z", tz="GMT")
    msapiversion<- "2018-03-28"
    signaturestring<-paste0("GET",paste(rep("\n",12),collapse=""),
                            "x-ms-date:",requestdate,
                            "x-ms-version:",msapiversion,"\n",
                            "mikeecutest", "\n",
                            "comp:list","\n",
                            "restype:container")

    headerstuff<-add_headers(Authorization=paste0("SharedKey mikeecutest/mike-ecu-test:",
                                                  RCurl::base64(digest::hmac(key=RCurl::base64Decode(sak, mode="raw"),
                                                                             object=enc2utf8(signaturestring),
                                                                             algo= "sha256", raw=TRUE))),
                             `x-ms-date`=requestdate,
                             `x-ms-version`=msapiversion)

    content(GET(url,config = headerstuff, verbose() ))

}

存储 API 版本2018-03-28 生成:

 <- HTTP/1.1 400 One of the request inputs is out of range.

存储 API 版本2018-02-01 生成:

 <- HTTP/1.1 400 The value for one of the HTTP headers is not in the correct format.

【问题讨论】:

  • 请求时间是UTC吗?

标签: r azure azure-storage


【解决方案1】:

您是对的,2017-01-19 不是有效的存储服务版本,请参阅所有版本here。文档文章Versioning for the Azure Storage services 还在顶部建议了最新的 API 版本。

如果没有特殊要求,建议您使用最新的。

更新

查看三点修复:

signaturestring<-paste0("GET",paste(rep("\n",12),collapse=""),
                            "x-ms-date:",requestdate,"\n",   # miss "\n"
                            "x-ms-version:",msapiversion,"\n",
                            "/mikeecutest/mike-ecu-test", "\n", # should be /accountname/containername
                            "comp:list","\n",
                            "restype:container")

headerstuff<-add_headers(Authorization=paste0("SharedKey mikeecutest:", # only need accountname here
                                                  RCurl::base64(digest::hmac(key=RCurl::base64Decode(sak, mode="raw"),
                                                                             object=enc2utf8(signaturestring),
                                                                             algo= "sha256", raw=TRUE))),
                             `x-ms-date`=requestdate,
                             `x-ms-version`=msapiversion)

REST API 包总是首选,你可以试试@Hong 提供的包。

【讨论】:

  • 谢谢,这 4 项更改奏效了。我可能会使用@Hong 的包,这就是我开始寻找的东西,并且害怕我不得不写它。
  • 只需更正版本即可解决我的问题。你的第一行文字救了我。谢谢@Jerry
【解决方案2】:

考虑使用我的 AzureStor 包,它是 Azure 上文件和 blob 存储的接口。它处理身份验证,包括访问密钥和 SAS,以及获取 API 版本等管理细节。

install.packages("AzureStor")
library(AzureStor)

bl <- blob_endpoint("http://mikeecutest.blob.core.windows.net",
                    key="your_key")

cont <- blob_container(bl, "mike-ecu-test")
list_blobs(cont)
upload_blob(cont, "srcfile", "destblob") # blocked upload is supported for blob storage
download_blob(cont, "srcblob", "destfile")

newcontainer <- create_blob_container(bl, "newcontainer")
delete_blob_container(newcontainer)

【讨论】:

    猜你喜欢
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    相关资源
    最近更新 更多