I've been trying to send an xml string through sockets from a client to a server. The idea is to parse this xml with ElementTree and then use the obtained element.
I can successfully pass the string from client to server, but regardless of how i build the xml in the client ( via file, triple quotes string or using the method within the ElementTree packages), in the server i keep getting the error
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
I have validated the file/string and I'm not sure where's the mistake since i really don't have any experience in directly using XML files.
This is the XML string
RemoteFunction = '''<?xml version="1.0"?>
<methodCall>
<methodName>somemethodname</methodName>
<params>
<param>
<value><string>somevalue</string></value>
</param>
<param>
<value><i4>1</i4></value>
</param>
<param>
<value><string>anothervalue</string></value>
</param>
</params>
</methodCall>'''
And this is the connection handler function in server
import xml.etree.ElementTree as ET
def client_handler( connection, address):
connected = True
while connected:
msgLen = connection.recv(64).decode("utf-8")
if msgLen:
msgLen = int(msgLen)
msg = connection.recv(msgLen).decode("utf-8")
if msg == "!Disconnect":
connected = False
tree = ET.fromstring(msg)
Note: I am aware there's a library for XMLRPC in Python3 but I'm not allowed to use it.
msgbefore trying to parse it as XML?msg<?xml version="1.0"?> <methodCall> <methodName>somemethodname</methodName> <params> <param> <value><string>somevalue</string></value> </param> <param> <value><i4>1</i4></value> </param> <param> <value><string>anothervalue</string></value> </param> </params> </methodCall>msgis valid xml which can be read fine by both ET and lxml.