mardi 10 mars 2020

Use or integrate Web API (XML petition) in Python

I need to integrate a web API in Python to be able to send SMS to a client list, but I don't know where to start.

Here's an example provided by the service I need to use to get the ping and know if the API is up, and I need to use it in Python:

POST https://sms.didimo.es/wcf/Service.svc/rest/Ping HTTP/1.1

<PingRequest xmlns="https://sms.didimo.es/wcf/PingRequest">
  <UserName>{:UserName}</UserName>
  <Password>{:Password}</Password>
</PingRequest>

Content-Type: application/xml
Accept: application/xml

This is what I tried, but doesn't work:

payload = {"UserName":"myusername", "Password":"mypassword"}

solicitud = requests.post("https://sms.didimo.es/wcf/Service.svc/rest/Ping", params = payload)

if solicitud.status_code == 200:
 print(solicitud.text)

if solicitud.status_code == 200:
    print(solicitud.text)
else: 
  print("Error")
  print(solicitud.status_code)

This is the help link they provide.

Any help, hint or guide on how to do it?




Aucun commentaire:

Enregistrer un commentaire