无法从 Azure Blob 存储下载文件
Inable to download file from Azure Blob Storage
我有一个 SSIS 包如何连接到 Azure 并将 json 文件恢复为配置文件。
直到有一天,在没有解释的情况下,我开始出错。
请注意连接成功,我的 IP 地址已列入白名单。
代码
115 StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
116 CloudStorageAccount storage = new CloudStorageAccount(credentials, true);
117 CloudBlobClient client = storage.CreateCloudBlobClient();
118 CloudBlobContainer blobContainer = client.GetContainerReference(configFileContainer);
119 CloudBlockBlob blob = blobContainer.GetBlockBlobReference(configFileName);
120
121 string configJson = blob.DownloadText(); // ERROR
错误
Client and server cannot communicate because they do not have any algorithms in common.
堆栈跟踪
Error: 0x1 at ST - Load Config: An error occurred while sending the request. at Microsoft.Azure.Storage.Core.Executor.Executor.<ExecuteAsync>d__1`1.MoveNext()
--- End of stack trace from previous location where the exception was raised ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Storage.Core.Executor.Executor.<>c__DisplayClass0_0`1.<ExecuteSync>b__0()
at Microsoft.Azure.Storage.Core.Util.CommonUtility.RunWithoutSynchronizationContext[T](Func`1 actionToRun)
at Microsoft.Azure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadRangeToStream(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadToStream(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlockBlob.DownloadText(Encoding encoding, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at ST_9b0ac6493260451aa379f7276b92d98e.ScriptMain.Main() dans ...344f55fca5c54a4f832c7376bc4a2b16\ScriptMain.cs:ligne 121
Error: 0x6 at ST - Load Config: The script returned an error result.
Task failed: ST - Load Config
问题是使用的连接协议已过时。 Azure 需要 TLS1.2 协议。
解决问题的两种方法:
- 在您的计算机上 => 启用 TLS 协议并禁用旧版本。
- 在代码中 => 禁用过时的协议并强制使用 TLS1.2 并在连接到 Azure 之前添加此代码。
像那样:
108 // Remove insecure protocols (SSL3, TLS 1.0, TLS 1.1)
109 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
110 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
111 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11;
112 // Add TLS 1.2
113 ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
114
115 StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
116 CloudStorageAccount storage = new CloudStorageAccount(credentials, true);
117 CloudBlobClient client = storage.CreateCloudBlobClient();
118 CloudBlobContainer blobContainer = client.GetContainerReference(configFileContainer);
119 CloudBlockBlob blob = blobContainer.GetBlockBlobReference(configFileName);
我有一个 SSIS 包如何连接到 Azure 并将 json 文件恢复为配置文件。 直到有一天,在没有解释的情况下,我开始出错。
请注意连接成功,我的 IP 地址已列入白名单。
代码
115 StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
116 CloudStorageAccount storage = new CloudStorageAccount(credentials, true);
117 CloudBlobClient client = storage.CreateCloudBlobClient();
118 CloudBlobContainer blobContainer = client.GetContainerReference(configFileContainer);
119 CloudBlockBlob blob = blobContainer.GetBlockBlobReference(configFileName);
120
121 string configJson = blob.DownloadText(); // ERROR
错误
Client and server cannot communicate because they do not have any algorithms in common.
堆栈跟踪
Error: 0x1 at ST - Load Config: An error occurred while sending the request. at Microsoft.Azure.Storage.Core.Executor.Executor.<ExecuteAsync>d__1`1.MoveNext()
--- End of stack trace from previous location where the exception was raised ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Storage.Core.Executor.Executor.<>c__DisplayClass0_0`1.<ExecuteSync>b__0()
at Microsoft.Azure.Storage.Core.Util.CommonUtility.RunWithoutSynchronizationContext[T](Func`1 actionToRun)
at Microsoft.Azure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadRangeToStream(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadToStream(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlockBlob.DownloadText(Encoding encoding, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at ST_9b0ac6493260451aa379f7276b92d98e.ScriptMain.Main() dans ...344f55fca5c54a4f832c7376bc4a2b16\ScriptMain.cs:ligne 121
Error: 0x6 at ST - Load Config: The script returned an error result.
Task failed: ST - Load Config
问题是使用的连接协议已过时。 Azure 需要 TLS1.2 协议。
解决问题的两种方法:
- 在您的计算机上 => 启用 TLS 协议并禁用旧版本。
- 在代码中 => 禁用过时的协议并强制使用 TLS1.2 并在连接到 Azure 之前添加此代码。
像那样:
108 // Remove insecure protocols (SSL3, TLS 1.0, TLS 1.1)
109 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
110 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
111 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11;
112 // Add TLS 1.2
113 ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
114
115 StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
116 CloudStorageAccount storage = new CloudStorageAccount(credentials, true);
117 CloudBlobClient client = storage.CreateCloudBlobClient();
118 CloudBlobContainer blobContainer = client.GetContainerReference(configFileContainer);
119 CloudBlockBlob blob = blobContainer.GetBlockBlobReference(configFileName);