gpt4 book ai didi

python - 找不到资源错误: When Reading CSV from Azure Blob using Pandas with its SAS URL

转载 作者:行者123 更新时间:2023-12-03 06:45:10 25 4
gpt4 key购买 nike

我正在尝试执行数据集版本控制,将 CSV 文件读入 pandas DataFrame,然后创建新版本的 Azure ML 数据集。我正在 Azure DevOps 中的 Azure CLI 作业中运行以下代码。

df = pd.read_csv(blob_sas_url)

在这一行,我收到 404 错误。错误消息:

urllib.error.HTTPError: HTTP Error 404: The specified resource does not exist

我尝试在本地执行此操作,我能够将 csv 文件读入 Dataframe。SAS URL 和 token 也没有过期。

如何解决这个问题?

编辑 - 代码

def __init__(self, args):
self.args = args
self.run = Run.get_context()
self.workspace = self.run.experiment.workspace

def get_Dataframe(self):

print(self.args.blob_sas_url)
df = pd.read_csv(self.args.blob_sas_url)

return df


def create_pipeline(self):
print("Creating Pipeline")
print(self.args.blob_sas_url)

dataframe = self.dataset_to_update()
# Rest of Code

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Azure ML Dataset Versioning pipeline')

parser.add_argument('--blob_sas_url', type=str, help='SAS URL to the Data File in Blob Storage')

args = parser.parse_args()
ds_versioner = Pipeline(args)
ds_versioner.create_pipeline()

在脚本 print(self.args.blob_sas_url) 中打印 SAS URL 的两个实例中,URL 均被缩短。我可以在 std_log.txt 文件中看到这一点。

最佳答案

缩短或从技术上修剪输入参数的原因是 bash 变量在 & 级别进行拆分。因此,您的 sas url 的其余部分都将作为“命令”或其他“参数”。显然,这就是 azure 解析它的方式。

例如:

python3 test_input.py --blob_sas_url "somepath/to/storage/account/file.txt?sv=2022-01-01&sr=b&sig=SOmethingwd21dd1"
>>> output: somepath/to/storage/account/file.txt?sv=2022-01-01&sr=b&sig=SOmethingwd21dd1

python3 test_input.py --blob_sas_url somepath/to/storage/account/file.txt?sv=2022-01-01&sr=b&sig=SOmethingwd21dd1
>>> output:
[1] 1961
[2] 1962
[2]+ Done sr=b

因此您只需在步骤命令中引用 Azure 变量,如下所示:

python3 your_python_script.py --blob_sas_url“$(azml.sasURL)”

关于python - 找不到资源错误: When Reading CSV from Azure Blob using Pandas with its SAS URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74179120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com