Python hadoop配置xml编码

Python hadoop配置xml编码,python,xml,hadoop,Python,Xml,Hadoop,我制作了一个python脚本来自动部署hadoop。 xml配置文件(如core-site.xml)由utf-8使用python脚本修改和编码。 但是hadoop无法读取这个xml文件 以下是我的xml经过脚本修改后: <?xml version='1.0' encoding='utf-8'?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Put site-specific pro

我制作了一个python脚本来自动部署hadoop。 xml配置文件(如core-site.xml)由utf-8使用python脚本修改和编码。 但是hadoop无法读取这个xml文件

以下是我的xml经过脚本修改后:

<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
    <property>
    <name>fs.default.name</name>
    <value>hdfs://c31:9000</value>
  </property>
</configuration>

臭虫在哪里?有人帮忙吗?

启动守护进程时是否看到任何错误?值得检查$HADOOP_HOME/logs吗?是的,名称或服务未知NSTNAME C31,当我手动修改xml时,它可以工作。
import lxml.etree

def modify_core_site(namenode_hostname):
    doc = lxml.etree.parse("pkg/core-site.xml")
    root = doc.getroot()
    print dir(root)
    # print root.getchildren()
    for child in root.iter("property"):
        name = child.find("name").text
        if name == "fs.default.name":
            text = "hdfs://%s:9000" % namenode_hostname
            child.find("value").text = text
    s = lxml.etree.tostring(doc, encoding="utf-8", xml_declaration = True, pretty_print = True)
    with open("pkg/core-site.xml", "w") as f:
        f.write(s)