python - 无法访问 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
我已经按照指示,仍然给我这个错误,有人知道如何解决吗?问题是我必须在数据湖上做的关键或一些配置?
解决方案
推荐阅读
- swift - Alamofire,Swift:什么可能导致此错误?
- javascript - 我怎样才能找到“td:nth-child”号码
- java - 使用 POI 在 Java 中的 Excel 中的标题右侧包含图像
- python - 如何在 MongoDB 中更新此数组?
- sql - 标量函数太慢 - 列中的计算字段
- python - 为什么 pyephem sublat 和 STK LLA 的结果不同?
- firebase - 如何使用 Flutter 在 Firestore 中的 uid 文档中创建集合?
- c++ - LNK2001 错误,即使 .cpp 正在编译
- python - TKinter 使 Frame 透明以显示底层小部件
- visual-studio - x64 程序集的新手,不确定为什么用户输入仍为 0