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

标签 python pandas azure azure-devops azure-machine-learning-service

我正在尝试执行数据集版本控制,将 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/

相关文章:

angular - 移动 safari : angular http call to .netcore 后端 - 0 未知错误

javascript - 通过django模板中数据属性的数值切换元素

python - 使用 pandas 通过文本相似度合并两个数据框

python-3.x - 为什么使用 .loc 引发 SettingWithCopyWarning?

c# - 在 Azure Blob 存储上创建文件副本

azure - DocumentDb SELECT 与 JOIN 不返回任何内容

python - 为什么我不能使用 `tests` 从我的 python 轮中排除 `exclude` 目录?

python - 我如何检查字符串是否是像 isalpha() 这样返回 bool 值的泰语

python - 如何在从属模式下运行 Kivy EventLoop?

python - pandas 中的广义系列拆分(一对多映射)