python - Weird characters in XML response -
i try communicate our supplier xml on http.
so far, request like:
post /some-service http/1.1 host: me content-type: text/xml; charset=utf-8 content-length: 470 <?xml version="1.0" ?> <pnarequest> <version>2.0</version> <transactionheader> <senderid>my company</senderid> <receiverid>my supplier</receiverid> <countrycode>fr</countrycode> <loginid>my login</loginid> <password>my password</password> <transactionid>some hexa numbers</transactionid> </transactionheader> <pnainformation quantity="1" sku="more numbers here"/> <showdetail>2</showdetail> </pnarequest>
(the content-length may differ, because changed body after i've pasted it.)
i send on port 443 of supplier, no encryption (testing purposes). before, had correct response, nice xml structure. now, have response this:
'\x15\x03\x00\x00\x02\x02\n'
i have displayed python using: print repr(response)
and full response, not body. no headers, nothing that.
on supplier side, don't see request in logs. so, clue of going on ? appreciated.
thanks !
update
here's python code sending request (note script test communication process, , see exchanged):
#!/usr/bin/env python # -*- coding: utf-8 -*- import re import socket def condense(body): body = re.sub(' +<','<', body) return body.replace('\n', '') def post(host, port, api, body, content_type="text/xml; charset=utf-8", me="my.ip"): body = condense(body) lines = [ "post {} http/1.1".format(api), "host: {}".format(me), "content-type: {}".format(content_type), "content-length: {}".format(len(body)), "", "{}".format(body), "", "", ] msg = "\r\n".join(lines) s = socket.create_connection((host, port)) s.send(msg) print "request ##############################################" print msg res = "" data = true while data: data = s.recv(8192) res += data s.close() print "response #############################################" print res print def unpack_post(d, **kwargs): post(d["host"], d["port"], d["api"], d["body"], **kwargs) my_supplier = { "host": "my.supplier.com", "port": 443, "api": "/some-api", "body": """<?xml version="1.0" ?> <pnarequest> <version>2.0</version> <transactionheader> <senderid>your company</senderid> <receiverid>my supplier</receiverid> <countrycode>fr</countrycode> <loginid>my login</loginid> <password>my password</password> <transactionid>some hexa numbers</transactionid> </transactionheader> <pnainformation quantity="1" sku="more numbers here"/> <showdetail>2</showdetail> </pnarequest>""", } if __name__ == "__main__": unpack_post(my_supplier)
i know little ugly, did testing purposes so... , wrote code because test on multiple servers, https://www.200please.com/, ...
so, saying in 1 of comments, due server side issue.
i know not perfect answer, since supplier don't share logs me, can guess things...
i'll edit answer later, if find new things share, don't since not programming issue anymore (again, guess here), not place that.
Comments
Post a Comment