如何在python中发布xml

如何在python中发布xml,python,xml,python-requests,Python,Xml,Python Requests,我试图将字符串作为xml发布,下面是代码: f = "<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap=

我试图将字符串作为xml发布,下面是代码:

     f = "<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <MakePaymentByServiceType xmlns="KioskSystems">
      <terminalId>1</terminalId>
      <serviceType>BBC</serviceType>
      <guid>asdfasd</guid>
      <requisite>123456</requisite>
      <amount>100</amount>
      <comission>decimal</comission>
      <user_comment>string</user_comment>
      <user_tin>string</user_tin>
      <user_address>string</user_address>
    </MakePaymentByServiceType>
  </soap:Body>
</soap:Envelope>"
    soup = BeautifulSoup(f, "xml")
    xml = soup.prettify()

    requests.post(url, data=xml)
我也尝试过这样的代码:

        with open('xmlfile.xml') as xml:
            r = requests.post(url, data=xml)
来自服务器的响应:

415
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
HTTP 415是不受支持的媒体类型-这表明您的请求丢失或内容类型标头不正确。尝试:

headers = {"Content-Type":"text/xml"}
r = requests.post(url, headers=headers, data=xml)
HTTP 415是不受支持的媒体类型-这表明您的请求丢失或内容类型标头不正确。尝试:

headers = {"Content-Type":"text/xml"}
r = requests.post(url, headers=headers, data=xml)

你为什么不用zeep?您的代码甚至不编译。显示您实际使用的代码。为什么不使用zeep?您的代码甚至不编译。显示您实际使用的代码。