简体   繁体   English

如何在python中发布xml

[英]how to post xml in python

i am trying to post string as xml, here is the code:我正在尝试将字符串发布为 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)

response from server:来自服务器的响应:

415

i also tried code like this:我也试过这样的代码:

        with open('xmlfile.xml') as xml:
            r = requests.post(url, data=xml)

response from server:来自服务器的响应:

    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

HTTP 415 is Unsupported Media Type - this suggest your request is missing or has incorrect Content-Type header. HTTP 415 是不受支持的媒体类型- 这表明您的请求丢失或包含不正确的Content-Type标头。 Try:尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM