1

I'm trying to convert a curl into a post on python with requests. I know that you typically write params = ('amount': '125') but this seems to have a header within the params and some nesting which is confusing the shit out of me:

curl -v -X POST https://sandbox.bluesnap.com/services/2/tools/param- 
encryption \
-H 'Content-Type: application/xml' \
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
-d '
<param-encryption xmlns="http://ws.plimus.com">
  <parameters>
    <parameter>
      <param-key>amount</param-key>
      <param-value>125.00</param-value>
    </parameter>
  </parameters>
</param-encryption>'

From: https://support.bluesnap.com/docs/creating-a-hosted-payments-page

Alec Davies
  • 127
  • 11

1 Answers1

0

It seems that you are trying to do a SOAP request. Try the following code:

import requests
url="https://sandbox.bluesnap.com/services/2/tools/param-encryption"
headers = {
  "content-type": "text/xml",
  "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
}
body = """
<param-encryption xmlns="http://ws.plimus.com">
  <parameters>
    <parameter>
      <param-key>amount</param-key>
      <param-value>125.00</param-value>
    </parameter>
  </parameters>
</param-encryption>"""
response = requests.post(url,data=body,headers=headers)
print response.content
Felipe Guerra
  • 145
  • 13
  • See this question to alternative solutions: https://stackoverflow.com/questions/18175489/sending-soap-request-using-python-requests – Felipe Guerra May 30 '18 at 14:57