Python Sax try to read an URL at the begining of an XML

84 Views Asked by At

I try to use SAX in Python to read a XML stream via a TCP port

data_to_parse = data()
data_table = {}
saxparser = make_parser()
saxparser.setContentHandler(data_to_parse)

data_to_print  = ''
data_xml = ''

try:
    while True:
        data_rec = client_sock.recv(1024)
        if not data_rec:
            break
        data_xml = data_rec.decode('utf-8')
        data_to_print = data_to_print + data_xml
        print(data_xml)
        saxparser.parse(data_xml) 

Here the XML stream I receive:

<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 2022-11-23 09:22:16 by Eclipse SUMO sumo Version 1.14.1
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
    .
    .
    .

But I get this error:

Unexpected err=URLError('unknown url type: ?xml version="1.0" encoding="utf-8"?>\n\n<!-- generated on 2022-11-23 09'), type(err)=<class 'urllib.error.URLError'>`

I don't understand why SAX talk about an URL. Does it expect an URL here? Do I miss something about SAX configuration ?

Answer are difficult to find on internet. Suggestion i found suppose to skip this xml part, but i would like to understand SAX.

0

There are 0 best solutions below