Reputation:
I'm trying to use SOAP API of movildata.com to get last location of a vehicle, using IMEI and api key, here is my code:
import requests
api_key = 'xxxxxxxxx'
imei = 'xxxxxxxxx'
request = """<?xml version = "1.0" encoding = "utf-8"?>
<soap12: Envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: soap12 = "http://www.w3.org/2003/05/soap-envelope">
<soap12: Body>
<getLastLocation xmlns = "http://ws.movildata.com/ws/wsUsers">
<apikey> {0} </ apikey>
<IMEI> {1} </ IMEI>
</ getLastLocation>
</ soap12: Body>
</ soap12: Envelope>
""".format(api_key, imei)
encoded_request = request.encode('utf-8')
headers = {"Host":"ws.movildata.com",
"Content-Type": "application/soap+xml; charset=utf-8",
"Content-Length":str(len(encoded_request))
}
response = requests.post(url='https://ws.movildata.com/wsUsers.asmx?op=getLastLocation',
headers=headers,
data=encoded_request
)
print(response.content)
print(response.status_code)
This returns XML response and HTTP status code 500
soap:ReceiverEl servidor no puede procesar la solicitud. ---> Un nombre no puede empezar con el car\xc3\xa1cter \' \', valor hexadecimal 0x20. L\xc3\xadnea 2, posici\xc3\xb3n 9.
I translated from spanish and it says something similar to
The server can not process the request. --- & gt; A name can not start with the character ' ';
I made sure the there wasn't any unnecessary empty space in request
but that didn't seem to change anything, any ideas what I might be doing wrong?
Upvotes: 1
Views: 289
Reputation: 12731
I have seen few errors of your XML formatting. Try correcting them as said below. If still getting the error, comment down below.
First in the namespace declarations in <soap12:
element, you can not have spaces between the xmlns
and xsi
.
correct all of them: xmlns:xsi
, xmlns:xsd
and xmlns:soap12
In <getLastLocation
, you just had xmlns
, without any variable name. Some parsers may not accept it. Give some dummy name (ex: xmlns:abc
).
In the closing elements, you have space between </
and element name.
Correct all below:
</getLastLocation>
</soap12:Body>
(Also remove space between :
and Body
)
</soap12:Envelope>
(Also remove space between :
and Envelope
)
Upvotes: 0