iT邦幫忙

0

[新手發問]在gcp上解析xml並存成csv失敗

  • 分享至 

  • xImage

在GCP中希望可以將先前上傳到值區的檔案解析後在別的值區另存成csv檔
修改後會顯示OSError: [Errno 30] Read-only file system: 'emic_text_1628469624.xml.csv'
不太懂新增一個csv檔為什麼會被回報只能讀
請問問題出在哪呢,謝謝各位大大

#開啟先前上傳的檔案
def main(event, context):
  download_blob(event['bucket'], event['name'], '/tmp/'+event['name'])
  filename = f"{event['name']}.csv"
  pat = '/tmp/'+event['name']
  _emic_csv_writer(pat , filename)
  upload_blob("emic-csv-cla", "/tmp/"+filename, filename)

#將該檔案解析後儲存為csv檔
def _emic_csv_writer(pat , filename):
  xmlparse = ET.parse( pat )
  root = xmlparse.getroot()
  rows = []
  cnt = 0

  for i in root[1].findall('{http://emic.eoc.gov.tw/disaster_info}DISASTER_DATA'):
      print(cnt)
      cnt += 1
      CASE_ID = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_ID").text
      CASE_DT = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_DT").text
      CASE_LOC = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_LOC").text
      DISASTER_MAIN_TYPE_NODE = i.find("{http://emic.eoc.gov.tw/disaster_info}DISASTER_MAIN_TYPE")
      DISASTER_MAIN_TYPE = "None" if DISASTER_MAIN_TYPE_NODE is None  else DISASTER_MAIN_TYPE_NODE.text
      CASE_DESCRIPTION = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_DESCRIPTION").text
      print(CASE_ID)
    
    
      rows.append({"CASE_ID": CASE_ID,
                   "CASE_DT": CASE_DT,
                   "CASE_LOC": CASE_LOC,
                   "DISASTER_MAIN_TYPE": DISASTER_MAIN_TYPE,
                   "CASE_DESCRIPTION": CASE_DESCRIPTION
                   })
    
  df = pd.DataFrame(rows)
  df.to_csv( filename , encoding = 'utf-8')
haward79 iT邦研究生 2 級 ‧ 2021-08-01 19:51:14 檢舉
有錯誤訊息嗎?
linken iT邦新手 5 級 ‧ 2021-08-02 15:22:34 檢舉
有但是沒有明說問題在哪
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.
linken iT邦新手 5 級 ‧ 2021-08-09 11:26:44 檢舉
修改後有更新錯誤訊息在問題裡了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答