首页 > 解决方案 > Python:发布 xml 文件

问题描述

我的xml文件:

<?xml version="1.0" ?>
<Task>
    <Date>2020-06-24</Date>
    <Time>10:40</Time>
    <Main>
        <Type>Car</Type>
        <Task1>Something</Task1>
        <Task2>Something</Task2>
        <Task3>Something</Task3>
        <Task4>Something</Task4>
        <Task5>RESULT</Task5>
        <Task6>1</Task6>
        <Task7>103</Task7>
        <Bill>
            <Type>$</Type>
            <Amount>100</Amount>
        </Bill>
        <Handball>false</Handball>
        <Football>false</Football>
        <Book>false</Book>
    </Main>
</Task>

我的代码.py

xmlFile = 'test.xml'
API_URL = XXX

    with open(xmlFile) as xml:
       r= requests.post(API_URL, data=xmlFile)
    print(r.text)

结果:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Status>
    <Code>ERROR_FORMAT_INVALID</Code>
    <Description>The supplied data could not be imported in the stated input format.</Description>
  </Status>
  <Status>
    <Code>ERROR</Code>
    <Description>The supplied data could not be imported in the stated input format - [XML2Array] Error parsing the XML string.</Description>
  </Status>
</Response>

我想要的是:

我有 200 个 XML 文件要发布(逐个文件)并接收数据。在这种情况下,请指定类型 $ 和金额“100”。我知道我会得到不同的结果,这就是为什么我想将所有 200 个 xml 文件的结果保存到一个 txt 文件中。

如下所示,我收到此错误。我怎样才能解决这个问题?

先感谢您

标签: pythonxml

解决方案


推荐阅读