首页 > 解决方案 > 无法访问 ADLS 数据,错误“响应”

问题描述

您好,我正在使用此代码访问 Azure 的 Data Lake gen 2 并读取 csv:

from azure.datalake.store import core, lib, multithread
import pandas as pd

tenant_id = '<your Azure AD tenant id>'
username = '<your username in AAD>'
password = '<your password>'
store_name = '<your ADL name>'
token = lib.auth(tenant_id, username, password)
# Or you can register an app to get client_id and client_secret to get token
# If you want to apply this code in your application, I recommended to do the authentication by client
# client_id = '<client id of your app registered in Azure AD, like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
# client_secret = '<your client secret>'
# token = lib.auth(tenant_id, client_id=client_id, client_secret=client_secret)

adl = core.AzureDLFileSystem(token, store_name=store_name)
f = adl.open('<your csv file path, such as data/test.csv in my ADL>')
df = pd.read_csv(f)

当我插入所有正确的数据时,我收到此错误:

----> 5 token = lib.auth(tenant_id, username, password)
      6 # Or you can register an app to get client_id and client_secret to get token
      7 # If you want to apply this code in your application, I recommended to do the authentication by client

/local_disk0/.ephemeral_nfs/envs/pythonEnv--------------/lib/python3.7/site-packages/azure/datalake/store/lib.py in auth(tenant_id, username, password, client_id, client_secret, resource, require_2fa, authority, retry_policy, **kwargs)
    148             raise ValueError("No authentication method found for credentials")
    149         return out
--> 150     out = get_token_internal()
    151 
    152     out.update({'access': out['accessToken'], 'resource': resource,

/local_disk0/.ephemeral_nfs/envs/pythonEnv-----------------/lib/python3.7/site-packages/azure/datalake/store/retry.py in f_retry(*args, **kwargs)
    104                     except:
    105                         pass
--> 106                 request_successful = last_exception is None or (response is not None and response.status_code == 401)  # 401 = Invalid credentials
    107                 if request_successful or not retry_policy.should_retry(response, last_exception, retry_count):
    108                     break

UnboundLocalError: local variable 'response' referenced before assignment

我已经按照指示,仍然给我这个错误,有人知道如何解决吗?问题是我必须在数据湖上做的关键或一些配置?

标签: pythonazurecsvazure-data-lake

解决方案


推荐阅读