user314644
user314644

Reputation: 13

How to send raw XML in Python?

I am trying to send raw xml to a service in Python. I have a the address of the service and my question is how would I wrap XML in python and send it to the service. The address is in the format below.

192.1100.2.2:54239

And say the XML is:

<xml version="1.0" encoding="UTF-8"><header/><body><code><body/>

Anyone know what to do?

Upvotes: 1

Views: 7962

Answers (2)

Rasmus Kaj
Rasmus Kaj

Reputation: 4360

pydoc socket

... should get you started.

PS. Your example IP address looks a bit strange (1100 is greater than 255), but maybe that's just so nobody tries to use it ...

Upvotes: 1

chrisg
chrisg

Reputation: 41675

This should do the trick.

import socket
import time

command = '<xml version="1.0" encoding="UTF-8"><header/><body><code><body/>'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.1100.2.2", 54239))

s.send(command)

time.sleep(2)
resp = s.recv(3000)

print resp

Upvotes: 7

Related Questions