Azure IOT ExportDevicesAsync 内部服务器错误

标签 azure iot azure-iot-hub

here 相同的问题。我正在关注simple sample to export the IOT设备列表到 blob 存储,但在 ExportDevicesAsync 上遇到内部服务器错误。 我正在使用北欧,但我认为更改服务器并不是真正有效的解决方案。

我得到的只是:

An exception of type 'Microsoft.Azure.Devices.Common.Exceptions.ServerErrorException' occurred in mscorlib.dll but was not handled in user code

Additional information: {"Message":"ErrorCode:ServerError;InternalServerError","ExceptionMessage":"Tracking ID:c51dad0227604f21b9af3e8acbd77f4c-G:5-TimeStamp:06/03/2017 19:56:10"}

示例代码(连接字符串和键屏蔽)

internal async Task GetAllDevices()
{

    var ConnectionString =
        "HostName=xxxx.azure-devices.net;SharedAccessKeyName=xxxxowner;SharedAccessKey=xxxxLr3xxxxXKKILLxxxxx";
   registryManager = RegistryManager.CreateFromConnectionString(ConnectionString);

    var key = "https://xxxxotblob1.blob.core.windows.newt/?sv=2016-05-31&ss=bfqt&srt=sco&sp=rwdlxxxxup&se=2017-06-04T04:42:14Z&st=2017-06-03T20:42:14Z&spr=https&sig=kxxxxxxxxxxxxxxx%3D";

    JobProperties exportJob = await registryManager.ExportDevicesAsync(key,"device.txt", false);

    while (true)
    {
        exportJob = await registryManager.GetJobAsync(exportJob.JobId);
        if (exportJob.Status == JobStatus.Completed ||
            exportJob.Status == JobStatus.Failed ||
            exportJob.Status == JobStatus.Cancelled)
        {
            break;
        }

        await Task.Delay(TimeSpan.FromSeconds(5));
    }

}

我在这里做错了什么吗?有没有办法捕获我错过的真正异常?

最佳答案

您的exportBlobContainerUri 格式可能有误。正确的看起来像这样:

https://[StorageAccountName].blob.core.windows.net/[ContainerName]?sv=2016-05-31&sr=c&sig=mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxw%3D&se=2017-06-06T02%3A07%3A22Z&sp=rwd

您可以按照以下步骤获取容器 SAS URI:

//1# Get your container:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

//2# Format the Uri:

static string GetContainerSasUri(CloudBlobContainer container)
{
  var sasConstraints = new SharedAccessBlobPolicy();
  sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24);
  sasConstraints.Permissions = 
    SharedAccessBlobPermissions.Write | 
    SharedAccessBlobPermissions.Read | 
    SharedAccessBlobPermissions.Delete;

  string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);

  return container.Uri + sasContainerToken;
}

更多信息可以引用Create a containerGet the container SAS URI .

关于Azure IOT ExportDevicesAsync 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44348071/

相关文章:

Azure IoT 中心消息路由路由查询仅识别所需属性中的更改

c# - 使用 Azure 服务总线发布/订阅

azure - Get-AzADAppPermission Id 转换器

python - 在 PyCharm 上的单个项目上运行两个文件

iot - 带有物联网传感器的 Apache Nifi

java - GridDB JAVA API 中的异常

c# - 如何从目录复制所有文件并将这些文件的副本移动到同一azure blob容器c#中的不同目录

javascript - 谁能告诉我是否可以在 wemos d1 mini 上刷新 javascript 代码?

java - 我可以使用什么 Java SDK 返回 IoT 中心中的设备列表

c# - 来自 IoT Edge 模块的 MySQL 连接