我正在嘗試針對Azure存儲API請求一個不公開的帳戶,並且需要進行身份驗證。與https使用Azure Blob存儲REST api
我試圖按照此頁面的標題: https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx
我根本無法進行這項工作。我總是收到一個「ResourceNotFound」錯誤,我無法解釋這個錯誤,因爲我絕對不會忘記存儲帳戶或容器名稱。我還使用相同的帳戶,容器和密鑰成功連接到Power BI。
我唯一能想到的可能是簽名的生成,我可能會在編碼中丟失(第一次我正在做這樣的事情)。但是這並不能解釋錯誤消息是「ResourceNotFound」。以下是請求(R)的代碼:
#azure storage endpoint to hit against
account <- "myaccount"
container <- "mycontainer"
requestProperties <- "comp=list"
endPoint <- paste("https://", account, ".blob.core.windows.net/", sep = "")
endPoint
#[1] "https://myaccount.blob.core.windows.net/"
#date header
timeStamp <- Sys.time()
timeString <- format(timeStamp, format="%y-%m-%d %H:%M:%S", tz="GMT", usetz = TRUE)
timeString <- "Fri, 30 Sep 2016 14:54:30 GMT"
dateHeader <- paste("x-ms-date", timeString, sep = ":")
dateHeader
#[1] "x-ms-date:Fri, 30 Sep 2016 14:54:30 GMT"
#version header
versionHeader <- "x-ms-version:2015-02-21"
#authorization header
requestVerb <- "GET"
authType <- "SharedKey"
azureKey <- "myAccountKey"
newLines <- "\n\n\n\n\n\n\n\n\n\n"
canonicalizedHeaders <- paste(dateHeader,versionHeader, sep = "\n")
#build canonicalized resource
resourceAccount <- paste("/",account, sep = "")
resourceContainer <- paste ("/",container, sep = "")
resource <- paste(resourceAccount, resourceContainer, sep = " ")
canonicalizedResource <- paste(resource, requestProperties, sep = "\n")
canonicalizedResource
#[1] "/myaccount /mycontainer\ncomp=list"
#build authentication signed string
stringToSign <- paste(requestVerb, newLines, canonicalizedHeaders, canonicalizedResource, sep = "\n")
stringToSign <- enc2utf8(stringToSign)
stringToSign
#[1] "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:Fri, 30 Sep 2016 14:54:30 GMT\nx-ms-version:2015-02-21\n/myaccount /mycontainer\ncomp=list"
Signature <- digest::hmac(object = stringToSign, key = azureKey, algo = "sha256", serialize = FALSE)
#authentication header
authorization <- paste(account, Signature, sep = ":")
authorization
#[1] "myaccount:b4761595ea09d0e9d56223bd0a14233bca2b9fc3bb043031586215942f5c6d06"
authHeader <- paste("Authorization:", authType, authorization, sep = " ")
authHeader
#[1] "Authorization: SharedKey myaccount:b4761595ea09d0e9d56223bd0a14233bca2b9fc3bb043031586215942f5c6d06"
#build the actual request
request <- paste(endPoint, requestProperties, sep = "?")
request
#[1] "https://myaccount.blob.core.windows.net/?comp=list"
azureRequest <- httr::GET(request, httr::add_headers(dateHeader, versionHeader, authHeader))
responseContent <- httr::content(azureRequest, as = "text")
responseContent
#[1] "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.\nRequestId:b1e87500-0001-0003-6231-1b7598000000\nTime:2016-09-30T15:44:52.3452448Z</Message></Error>"
我是否在生成請求時缺少某些內容?我是否需要使用我的帳戶進行操作以允許通過REST API訪問?
因此,爲了演示的目的,MS是否提供了公開可用的驗證密鑰的虛擬帳戶?否則,你應該去一些特定於Azure的論壇,因爲剩下的我們非Azure用戶將無法測試任何答案。 –
我希望這不是你真正的SharedKey – Paparazzi
嘗試將容器放在路徑中。例如http:// .blob.core.windows.net/mycontainer –
Paparazzi