0

I am new in python. I need to get the data based via url. The data is based on a unique number which is in payload. I can't seem to find a way to initiate a variable in "CUSTNO" in payload and iterate it. iterate it. (I have removed some of the payload data)

url = 'url'

payload = "<CHANNELID></CHANNELID>\r\n  </FCDB_HEADER>\r\n  <FCDB_BODY>\r\n    <CUSTOMER>\r\n      " \    
          "<CUSTNO>123456789</CUSTNO>\r\n    </CUSTOMER>\r\n"

response = requests.request("POST", url, data=payload, headers=headers)
xml_response = response.text
print(xml_response)

2 Answers 2

2

Below (assuming that you want to change the customer number)

url = 'url'

customer_no = 4562

payload = "<CHANNELID></CHANNELID>\r\n  </FCDB_HEADER>\r\n  <FCDB_BODY>\r\n    <CUSTOMER>\r\n      " \    
          "<CUSTNO>{}</CUSTNO>\r\n    </CUSTOMER>\r\n"

response = requests.request("POST", url, data=payload.format(customer_no), headers=headers)
xml_response = response.text
print(xml_response)
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect. It worked, Thanks alot. Any idea how to change the xml response into python dictionary?
@AliKhan I am glad to help. Feel free to mark the answer as helpful.
0

Your question is really unclear! Maybe your payload formatting is wrong. Which version of Python are you using?

Try this:

payload = '''<CHANNELID></CHANNELID>\r\n  </FCDB_HEADER>\r\n  <FCDB_BODY>\r\n    <CUSTOMER>\r\n       \    
      <CUSTNO>123456789</CUSTNO>\r\n    </CUSTOMER>\r\n'''

2 Comments

I took the payload code from postman. I have deleted some of the data before posting here. I am using 3.7. I just want to make the <CUSTNO> a variable and insert the data with loop. could it be possible?
Sorry, I really cannot make sense of your question. Improve your question and then maybe someone can help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.