1

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?

2
  • possible duplicate of stackoverflow.com/questions/415192/… Commented Apr 12, 2010 at 15:13
  • 1
    (That's neither a valid IP address nor well-formed XML.) Commented Apr 12, 2010 at 15:50

2 Answers 2

7

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
Sign up to request clarification or add additional context in comments.

Comments

1
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 ...

1 Comment

IP address is indeed invalid.

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.