diff --git a/async_upnp_client/server.py b/async_upnp_client/server.py index 7aa3ca56..df4e6e88 100644 --- a/async_upnp_client/server.py +++ b/async_upnp_client/server.py @@ -394,9 +394,7 @@ async def async_send_events( continue prop_el = ET.SubElement(event_el, "e:property") ET.SubElement(prop_el, state_var.name).text = str(state_var.value) - message = ( - '\n' + ET.tostring(event_el, encoding="utf-8").decode() - ) + message = ET.tostring(event_el, encoding="utf-8", xml_declaration=True).decode() headers = { "CONTENT-TYPE": 'text/xml; charset="utf-8"', @@ -1128,7 +1126,7 @@ def _create_action_response( return Response( content_type="text/xml", charset="utf-8", - body=ET.tostring(envelope_el, encoding="utf-8"), + body=ET.tostring(envelope_el, encoding="utf-8", xml_declaration=True), ) @@ -1163,7 +1161,7 @@ def _create_error_action_response( status=500, content_type="text/xml", charset="utf-8", - body=ET.tostring(envelope_el, encoding="utf-8"), + body=ET.tostring(envelope_el, encoding="utf-8", xml_declaration=True), ) @@ -1243,7 +1241,7 @@ async def to_xml( serializer = UpnpXmlSerializer() thing_el = serializer.to_xml(thing) encoding = "utf-8" - thing_xml = ET.tostring(thing_el, encoding=encoding) + thing_xml = ET.tostring(thing_el, encoding=encoding, xml_declaration=True) return Response(content_type="text/xml", charset=encoding, body=thing_xml) diff --git a/changes/243.bugfix b/changes/243.bugfix new file mode 100644 index 00000000..8256a3d4 --- /dev/null +++ b/changes/243.bugfix @@ -0,0 +1 @@ +Add proper XML preamble in server communication. diff --git a/tests/fixtures/server/action_response.xml b/tests/fixtures/server/action_response.xml index f9a6ce6a..fe968b42 100644 --- a/tests/fixtures/server/action_response.xml +++ b/tests/fixtures/server/action_response.xml @@ -1 +1,2 @@ + foo0 diff --git a/tests/fixtures/server/device.xml b/tests/fixtures/server/device.xml index c058732b..6600fce1 100644 --- a/tests/fixtures/server/device.xml +++ b/tests/fixtures/server/device.xml @@ -1 +1,2 @@ + 10:urn:schemas-upnp-org:device:TestServerDevice:1Test ServerTestTest ServerTestServerv0.0.10000001uuid:adca2e25-cbe4-427a-a5c3-9b5931e7b79burn:schemas-upnp-org:service:TestServerService:1urn:upnp-org:serviceId:TestServerService/upnp/control/TestServerService/upnp/event/TestServerService/ContentDirectory.xml diff --git a/tests/fixtures/server/subscribe_response_0.xml b/tests/fixtures/server/subscribe_response_0.xml index c4b52e7f..663d9850 100644 --- a/tests/fixtures/server/subscribe_response_0.xml +++ b/tests/fixtures/server/subscribe_response_0.xml @@ -1,2 +1,2 @@ - + 0 diff --git a/tests/fixtures/server/subscribe_response_1.xml b/tests/fixtures/server/subscribe_response_1.xml index 6cec63d3..4203394e 100644 --- a/tests/fixtures/server/subscribe_response_1.xml +++ b/tests/fixtures/server/subscribe_response_1.xml @@ -1,2 +1,2 @@ - + 1