如何在python中解析xml S3存储桶

时间:2019-06-26 08:49:51

标签: amazon-s3

无法从s3存储桶中解析xml

这是来自S3存储桶的响应:

<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Name>example-bucket</Name>
  <Prefix>photos/2006/</Prefix>
  <Marker></Marker>
  <MaxKeys>1000</MaxKeys>
  <Delimiter>/</Delimiter>
  <IsTruncated>false</IsTruncated>

  <CommonPrefixes>
    <Prefix>photos/2006/February/</Prefix>
  </CommonPrefixes>
  <CommonPrefixes>
    <Prefix>photos/2006/January/</Prefix>
  </CommonPrefixes>
</ListBucketResult>

当我使用此代码进行解析

import xml.etree.ElementTree as ET
root = ET.fromstring(data)
print root

结果是:

<Element '{http://s3.amazonaws.com/doc/2006-03-01/}ListBucketResult' at 0x7f8f38482110>

结果不应包含“ {http://s3.amazonaws.com/doc/2006-03-01/}”

0 个答案:

没有答案