无法连接到本地存储帐户

时间:2021-04-08 14:38:15

标签: azure-iot-edge

我按照 Microsoft 文档部署存储帐户边缘模块,我的模块当前正在我的 VM 中运行。 但是,我无法将 Python SDK 或存储资源管理器连接到它。

我的容器创建选项是:

{
"Env": [
    "localstorage",
    "92RhvUXR59Aa8h90LSHC7w=="
],
"HostConfig": {
    "Binds": [
        "blobvolume:/blobroot"
    ],
    "PortBindings": {
        "11002/tcp": [
            {
                "HostPort": "11002"
            }
        ]
    }
}
}

我的模块孪生设置是

{
"deviceAutoDeleteProperties": {
    "deleteOn": false,
    "deleteAfterMinutes": 0,
    "retainWhileUploading": true
},
"deviceToCloudUploadProperties": {
    "uploadOn": true,
    "uploadOrder": "OldestFirst",
    "cloudStorageConnectionString": "<<my connection string was here :) >>",
    "storageContainersForUpload": {
        "eds-container-pcu": {
            "target": "eds-container-pcu"
        }
    },
    "deleteAfterUpload": true
}
}

iotedge 列表说

blobstorage      running          Up 5 hours       mcr.microsoft.com/azure-blob-storage:latest

我还检查了音量。我将一个文件放入卷中的“BlockBlob”文件夹中,然后进入容器的外壳,在 /blobroot 下我可以找到该文件。

我还复制了云存储连接字符串并将其用于文件上传,这也有效。我可以成功将文本文件上传到我的云存储帐户。

我的本​​地存储帐户的连接字符串就是那个,不是吗?我自己创建的,就像文档说的:

DefaultEndpointsProtocol=http;BlobEndpoint=http://localhost:11002/localstorage;AccountName=localstorage;AccountKey=92RhvUXR59Aa8h90LSHC7w==;

使用该连接字符串,我无法连接任何东西。不是 SDK,也不是存储资源管理器。

Python 代码为:

    CONNECTION_STRING = "DefaultEndpointsProtocol=http;BlobEndpoint=http://localhost:11002/localstorage;AccountName=localstorage;AccountKey=92RhvUXR59Aa8h90LSHC7w==;"
    blobClient = BlobClient.from_connection_string(CONNECTION_STRING, "eds-container-pcu", "test123.txt")
    # Doesn't work with or without this line
    blobClient._X_MS_VERSION = '2017-04-17'
    blobClient.upload_blob(data="Hello World", blob_type="BlockBlob")

我得到:

HttpResponseError: Server encountered an internal error. Please try again after some time.
RequestId:fef9066d-323c-47e3-8e6f-ba006557ee65
Time:2021-04-08T14:33:23.7892893Z
ErrorCode:InternalError
Error:None
ExceptionDetails:None
ExceptionMessage:'s' cannot be null
StackTrace:AsyncHelper.ArgumentNullRethrowableException: 's' cannot be null
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 's')
   at System.Convert.FromBase64String(String s)
   at Microsoft.AzureStack.Services.Storage.FrontEnd.WossProvider.WStorageAccount..ctor(WStorageStamp stamp, String accountName)
   at Microsoft.AzureStack.Services.Storage.FrontEnd.WossProvider.WStorageStamp.Microsoft.Cis.Services.Nephos.Common.Storage.IStorageStamp.CreateAccountInstance(String accountName, ITableServerCommandFactory tableServerCommandFactory)
   at Microsoft.Cis.Services.Nephos.Common.Storage.PerRequestStorageManager.CreateAccountInstance(String accountName)
   at Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.BasicHttpProcessorWithAuthAndAccountContainer`1.GetResourceAccountPropertiesImpl(String accountName, Boolean isAdminAccess, TimeSpan timeout, AsyncIteratorContext`1 context)+MoveNext()
   at AsyncHelper.AsyncIteratorContextBase.ExecuteIterator(Boolean inBegin)
   --- End of inner exception stack trace ---
   at Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.BasicHttpProcessorWithAuthAndAccountContainer`1.EndGetResourceAccountProperties(IAsyncResult asyncResult)
   at Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.BasicHttpProcessorWithAuthAndAccountContainer`1.ProcessImpl(AsyncIteratorContext`1 async)+MoveNext()

为什么会这样?存储资源管理器也没有连接,上面的代码行与我的云存储连接字符串正常工作。

2 个答案:

答案 0 :(得分:1)

一位同事指出我的本地帐户密钥太短了。正如文档中所写,密钥的长度必须为 64 字节。与 SDK 或 StorageExplorer 的连接就可以了。我的代码也没有创建本地容器,但错误消息会说明这一点。

答案 1 :(得分:0)

在您的容器创建选项示例中,我缺少密钥(LOCAL_STORAGE_ACCOUNT_NAME 和 LOCAL_STORAGE_ACCOUNT_KEY)。您是否只指定了值?

"Env": [
    "LOCAL_STORAGE_ACCOUNT_NAME=localstorage",
    "LOCAL_STORAGE_ACCOUNT_KEY=92RhvUXR59Aa8h90LSHC7w=="
  ],

当我使用设置部署模块时,我可以通过存储资源管理器进行连接。

你有没有看 blob 存储模块的日志?