i am trying to post string as xml, here is the code:
JavaScript
x
21
21
1
f = "<?xml version="1.0" encoding="utf-8"?>
2
<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/">
3
<soap:Body>
4
<MakePaymentByServiceType xmlns="KioskSystems">
5
<terminalId>1</terminalId>
6
<serviceType>BBC</serviceType>
7
<guid>asdfasd</guid>
8
<requisite>123456</requisite>
9
<amount>100</amount>
10
<comission>decimal</comission>
11
<user_comment>string</user_comment>
12
<user_tin>string</user_tin>
13
<user_address>string</user_address>
14
</MakePaymentByServiceType>
15
</soap:Body>
16
</soap:Envelope>"
17
soup = BeautifulSoup(f, "xml")
18
xml = soup.prettify()
19
20
requests.post(url, data=xml)
21
response from server:
JavaScript
1
2
1
415
2
i also tried code like this:
JavaScript
1
3
1
with open('xmlfile.xml') as xml:
2
r = requests.post(url, data=xml)
3
response from server:
JavaScript
1
3
1
raise ConnectionError(err, request=request)
2
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
3
Advertisement
Answer
HTTP 415 is Unsupported Media Type – this suggest your request is missing or has incorrect Content-Type
header. Try:
JavaScript
1
3
1
headers = {"Content-Type":"text/xml"}
2
r = requests.post(url, headers=headers, data=xml)
3