Azure Databricks 语句执行 API:如何克服“Azure 存储请求未授权”错误

问题描述 投票:0回答:1

我正在尝试通过 C# .NET 应用程序中的语句执行 API 查询 Azure Databricks delta Lake。这是应用程序代码:

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace DatabricksApiApp
{
    class Program
    {
        static readonly HttpClient client = new HttpClient();

        static async Task Main(string[] args)
        {
            try
            {
                // Set up the endpoint and the access token
                string baseUrl = "https://adb-7765225718529619.19.azuredatabricks.net/api/2.0/sql/statements";
                string accessToken = "dapbmi7a544bbc6d0e05a1ec650b85570b70";
                string warehouseId = "ff9d6456ff77bcs84";

                // Prepare the HTTP request
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, baseUrl)
                {
                    Content = new StringContent(
                        "{\"statement\":\"SELECT * FROM maindev.default.product_1\", \"warehouse_id\":\"ff9d6456ff77bcs84\", \"timeout_seconds\":600}",
                        Encoding.UTF8,
                        "application/json"
                    )
                };
                request.Headers.Add("Authorization", $"Bearer {accessToken}");

                // Send the request
                HttpResponseMessage response = await client.SendAsync(request);

                // Check the response
                if (response.IsSuccessStatusCode)
                {
                    string responseBody = await response.Content.ReadAsStringAsync();
                    Console.WriteLine("Data retrieved successfully!");
                    Console.WriteLine(responseBody);
                }
                else
                {
                    Console.WriteLine($"Failed to retrieve data. Status code: {response.StatusCode}");
                    string responseBody = await response.Content.ReadAsStringAsync();
                    Console.WriteLine($"Response Body: {responseBody}");
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }
        }
    }
}

请求顺利到达 Databricks。据我了解,为了将数据返回到我的应用程序,此请求需要使用一些 Azure 存储。这是我收到此错误的地方:

This Azure storage request is not authorized. The storage account's 'Firewalls and virtual networks' settings may be blocking access to storage services. Please verify your Azure storage credentials or firewall exception settings.

正如您所知,该错误并未指定需要授权哪些特定存储。 我该怎么做才能克服这个错误?

azure azure-blob-storage databricks azure-storage azure-databricks
1个回答
0
投票

此问题与使用 services sql 仓库有关。我们的安全措施不允许外部实体访问我们的内部存储。一旦我们切换到专用的 sql 仓库 - 就没有问题了。

© www.soinside.com 2019 - 2024. All rights reserved.