簡體   English   中英

Azure Databricks在Blob存儲上打開文件的問題

[英]Problems with Azure Databricks opening a file on the Blob Storage

使用Azure Databricks,我可以列出blob存儲中的文件,並將它們放在一個數組中。 但是,當我嘗試打開一個文件時,出現錯誤。 可能是由於特殊的語法。

storage_account_name = "tesb"
storage_container_name = "rttracking-in"
storage_account_access_key = "xyz"
file_location = "wasbs://rttracking-in"
file_type = "xml"

spark.conf.set(
  "fs.azure.account.key."+storage_account_name+".blob.core.windows.net",
  storage_account_access_key)

xmlfiles = dbutils.fs.ls("wasbs://"+storage_container_name+"@"+storage_account_name+".blob.core.windows.net/")

import pandas as pd
import xml.etree.ElementTree as ET
import re
import os

firstfile = xmlfiles[0].path
root = ET.parse(firstfile).getroot()

錯誤是

IOError:[Errno 2]沒有這樣的文件或目錄:u'wasbs://rttracking-in@tstoweuyptoesb.blob.core.windows.net/rtTracking_00001.xml'

我的猜測是ET.parse()不知道您在其中建立與存儲帳戶的連接的Spark上下文。 或者,您可以嘗試安裝存儲。 然后,您可以通過本機路徑訪問文件,就像文件是本地文件一樣。

參見此處: https : //docs.databricks.com/spark/latest/data-sources/azure/azure-storage.html#mount-an-azure-blob-storage-container

然后應該可以工作:

root = ET.parse("/mnt/<mount-name>/...")

我確實安裝了存儲,然后就可以了

firstfile = xmlfiles [0] .path.replace('dbfs:','/ dbfs')root = ET.parse(firstfile).getroot()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM