# lxml.etree.XMLSyntaxError using python3.6

**URL:** <https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940>\
**Category:** Ansible Project\
**Created:** [October 1, 2020, 12:37pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940 "2020-10-01T12:37:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelo\_coluni](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@angelo\_coluni](https://forum.ansible.com/u/angelo_coluni)\
**Post date:** [October 1, 2020, 12:37pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/1 "2020-10-01T12:37:46Z")

</div>

Setup:

ansible 2.9.13

config file = /etc/ansible/ansible.cfg  
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python3.6/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

installed lxml-4.5.2 ncclient-0.6.9

Having an issue in ansible when using module netconf\_rpc, the following error occurs, however when I change interpreter\_python = /usr/bin/python2.7 error is not present

Any reason what can be causing this issue

thanks…

\<10.10.10.10\> EXEC /bin/sh -c ‘/usr/bin/python3.6 /root/.ansible/tmp/ansible-local-9652MobtmE/ansible-tmp-1601554935.02-9754-119778420816035/AnsiballZ\_netconf\_rpc.py && sleep 0’  
\<10.10.10.10\> EXEC /bin/sh -c ‘rm -f -r /root/.ansible/tmp/ansible-local-9652MobtmE/ansible-tmp-1601554935.02-9754-119778420816035/ \> /dev/null 2\>&1 && sleep 0’  
The full traceback is:  
Traceback (most recent call last):  
File “/root/.ansible/tmp/ansible-local-9652MobtmE/ansible-tmp-1601554935.02-9754-119778420816035/AnsiballZ\_netconf\_rpc.py”, line 102, in   
\_ansiballz\_main()  
File “/root/.ansible/tmp/ansible-local-9652MobtmE/ansible-tmp-1601554935.02-9754-119778420816035/AnsiballZ\_netconf\_rpc.py”, line 94, in \_ansiballz\_main  
invoke\_module(zipped\_mod, temp\_path, ANSIBALLZ\_PARAMS)  
File “/root/.ansible/tmp/ansible-local-9652MobtmE/ansible-tmp-1601554935.02-9754-119778420816035/AnsiballZ\_netconf\_rpc.py”, line 40, in invoke\_module  
runpy.run\_module(mod\_name=‘ansible.modules.network.netconf.netconf\_rpc’, init\_globals=None, run\_name=‘ **main** ’, alter\_sys=True)  
File “/usr/lib64/python3.6/runpy.py”, line 205, in run\_module  
return \_run\_module\_code(code, init\_globals, run\_name, mod\_spec)  
File “/usr/lib64/python3.6/runpy.py”, line 96, in \_run\_module\_code  
mod\_name, mod\_spec, pkg\_name, script\_name)  
File “/usr/lib64/python3.6/runpy.py”, line 85, in _run\_code  
exec(code, run\_globals)  
File “/tmp/ansible\_netconf\_rpc\_payload\_t8kmcb46/ansible\_netconf\_rpc\_payload.zip/ansible/modules/network/netconf/netconf\_rpc.py”, line 264, in   
File “/tmp/ansible\_netconf\_rpc\_payload\_t8kmcb46/ansible\_netconf\_rpc\_payload.zip/ansible/modules/network/netconf/netconf\_rpc.py”, line 246, in main  
File “/tmp/ansible\_netconf\_rpc\_payload\_t8kmcb46/ansible\_netconf\_rpc\_payload.zip/ansible/module\_utils/network/common/netconf.py”, line 141, in remove\_namespaces  
File "/usr/local/lib/python3.6/site-packages/ncclient/xml_.py", line 174, in **init**  
self.\_\_doc = self.remove\_namespaces(self.\__result)  
File "/usr/local/lib/python3.6/site-packages/ncclient/xml_.py", line 222, in remove\_namespaces  
parser=self.\_\_parser))),  
File “src/lxml/etree.pyx”, line 3521, in lxml.etree.parse  
File “src/lxml/parser.pxi”, line 1876, in lxml.etree.\_parseDocument  
File “src/lxml/parser.pxi”, line 1896, in lxml.etree.\_parseMemoryDocument  
File “src/lxml/parser.pxi”, line 1777, in lxml.etree.\_parseDoc  
File “src/lxml/parser.pxi”, line 1082, in lxml.etree.\_BaseParser.\_parseUnicodeDoc  
File “src/lxml/parser.pxi”, line 615, in lxml.etree.\_ParserContext.\_handleParseResultDoc  
File “src/lxml/parser.pxi”, line 725, in lxml.etree.\_handleParseResult  
File “src/lxml/parser.pxi”, line 654, in lxml.etree.\_raiseParseError  
File “”, line 1  
lxml.etree.XMLSyntaxError: Start tag expected, ‘\<’ not found, line 1, column 1

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 1, 2020, 12:49pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/2 "2020-10-01T12:49:42Z")

</div>

The netconf\_rpc module does not require lxml, but jxmlease instead.  
Make sure that is installed (as per docs  
[https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/netconf\_rpc\_module.html#requirements](https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/netconf_rpc_module.html#requirements)).

This is true for both of your python environments.  
Probably 'pip list' will show it's installed, while 'pip3 list' won't.

DIck

---

<div class="post-metadata">

**Author:** ![angelo\_coluni](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@angelo\_coluni](https://forum.ansible.com/u/angelo_coluni)\
**Post date:** [October 1, 2020, 3:41pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/3 "2020-10-01T15:41:27Z")

</div>

jxmlease is required if we want to display and store response in json,  
however if we want output to be xml we need lxml  
issue seems to be in removing name space from rpc reply , this could  
be ansible issue

thanks

ex:

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [October 1, 2020, 3:58pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/4 "2020-10-01T15:58:04Z")

</div>

It looks like it is failing while parsing the response.  
Please enable the persistent logging to identify exactly which RPC response is failing  
Refer:[https://docs.ansible.com/ansible/devel/network/user\_guide/network\_debug\_troubleshooting.html#enabling-networking-device-interaction-logging](https://docs.ansible.com/ansible/devel/network/user_guide/network_debug_troubleshooting.html#enabling-networking-device-interaction-logging)

---

<div class="post-metadata">

**Author:** ![angelo\_coluni](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@angelo\_coluni](https://forum.ansible.com/u/angelo_coluni)\
**Post date:** [October 1, 2020, 6:44pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/5 "2020-10-01T18:44:30Z")

</div>

Here is the output..I cannot see any issue

thanks

2020-10-01 14:08:46,140 p=862827 u=root n=ncclient.transport.ssh |  
[host 10.212.12.16 session-id 148] Received message from host  
2020-10-01 14:08:46,141 p=862827 u=root n=ansible | jsonrpc response:  
{"jsonrpc": "2.0", "id": "d9df6042-c78a-486a-b9c3-6e2b38083fb6",  
"result": "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\>\<data  
xmlns:fabrics=\"urn:kaloom:faas:fabrics\"  
xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"  
xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\"\>\<fabrics:Fabric\>\<fabrics:FabricID\>212\</fabrics:FabricID\>\<fabrics:Node\>\<fabrics:NodeID\>e9fa6779-c667-4733-8db2-61f904b8205e\</fabrics:NodeID\>\<fabrics:Name\>aj08025933-upf-31u\</fabrics:Name\>\</fabrics:Node\>\<fabrics:Node\>\<fabrics:NodeID\>ab48b157-fd08-46af-9355-5384e90979b4\</fabrics:NodeID\>\<fabrics:Name\>ak18000735-leaf-29u\</fabrics:Name\>\</fabrics:Node\>\<fabrics:Node\>\<fabrics:NodeID\>1c6e769f-02f0-41f7-a0f5-957d54d6e788\</fabrics:NodeID\>\<fabrics:Name\>controller-1\</fabrics:Name\>\</fabrics:Node\>\</fabrics:Fabric\>\</data\>"}  
2020-10-01 14:08:46,161 p=862943 u=root n=ansible | \<10.212.12.16\>  
EXEC /bin/sh -c 'rm -f -r  
/root/.ansible/tmp/ansible-local-862814\_qg5scng/ansible-tmp-1601575725.3798058-862943-225523550103615/

> /dev/null 2\>&1 && sleep 0'

2020-10-01 14:08:46,174 p=862814 u=root n=ansible | The full traceback is:  
Traceback (most recent call last):  
&nbsp;&nbsp;File "/root/.ansible/tmp/ansible-local-862814\_qg5scng/ansible-tmp-1601575725.3798058-862943-225523550103615/AnsiballZ\_netconf\_rpc.py",  
line 102, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;\_ansiballz\_main()  
&nbsp;&nbsp;File "/root/.ansible/tmp/ansible-local-862814\_qg5scng/ansible-tmp-1601575725.3798058-862943-225523550103615/AnsiballZ\_netconf\_rpc.py",  
line 94, in \_ansiballz\_main  
&nbsp;&nbsp;&nbsp;&nbsp;invoke\_module(zipped\_mod, temp\_path, ANSIBALLZ\_PARAMS)  
&nbsp;&nbsp;File "/root/.ansible/tmp/ansible-local-862814\_qg5scng/ansible-tmp-1601575725.3798058-862943-225523550103615/AnsiballZ\_netconf\_rpc.py",  
line 40, in invoke\_module  
&nbsp;&nbsp;&nbsp;&nbsp;runpy.run\_module(mod\_name='ansible.modules.network.netconf.netconf\_rpc',  
init\_globals=None, run\_name='\_\_main\_\_', alter\_sys=True)  
&nbsp;&nbsp;File "/usr/lib64/python3.6/runpy.py", line 205, in run\_module  
&nbsp;&nbsp;&nbsp;&nbsp;return \_run\_module\_code(code, init\_globals, run\_name, mod\_spec)  
&nbsp;&nbsp;File "/usr/lib64/python3.6/runpy.py", line 96, in \_run\_module\_code  
&nbsp;&nbsp;&nbsp;&nbsp;mod\_name, mod\_spec, pkg\_name, script\_name)  
&nbsp;&nbsp;File "/usr/lib64/python3.6/runpy.py", line 85, in \_run\_code  
&nbsp;&nbsp;&nbsp;&nbsp;exec(code, run\_globals)  
&nbsp;&nbsp;File "/tmp/ansible\_netconf\_rpc\_payload\_ci30aiuw/ansible\_netconf\_rpc\_payload.zip/ansible/modules/network/netconf/netconf\_rpc.py",  
line 264, in \<module\>  
&nbsp;&nbsp;File "/tmp/ansible\_netconf\_rpc\_payload\_ci30aiuw/ansible\_netconf\_rpc\_payload.zip/ansible/modules/network/netconf/netconf\_rpc.py",  
line 246, in main  
&nbsp;&nbsp;File "/tmp/ansible\_netconf\_rpc\_payload\_ci30aiuw/ansible\_netconf\_rpc\_payload.zip/ansible/module\_utils/network/common/netconf.py",  
line 141, in remove\_namespaces  
&nbsp;&nbsp;File "/usr/local/lib/python3.6/site-packages/ncclient/xml\_.py", line  
174, in \_\_init\_\_  
&nbsp;&nbsp;&nbsp;&nbsp;self.\_\_doc = self.remove\_namespaces(self.\_\_result)  
&nbsp;&nbsp;File "/usr/local/lib/python3.6/site-packages/ncclient/xml\_.py", line  
222, in remove\_namespaces  
&nbsp;&nbsp;&nbsp;&nbsp;parser=self.\_\_parser))),  
&nbsp;&nbsp;File "src/lxml/etree.pyx", line 3467, in lxml.etree.parse  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 1856, in lxml.etree.\_parseDocument  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 1876, in lxml.etree.\_parseMemoryDocument  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 1757, in lxml.etree.\_parseDoc  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 1068, in  
lxml.etree.\_BaseParser.\_parseUnicodeDoc  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 601, in  
lxml.etree.\_ParserContext.\_handleParseResultDoc  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 711, in lxml.etree.\_handleParseResult  
&nbsp;&nbsp;File "src/lxml/parser.pxi", line 640, in lxml.etree.\_raiseParseError  
&nbsp;&nbsp;File "\<string\>", line 1  
lxml.etree.XMLSyntaxError: Start tag expected, '\<' not found, line 1, column 1

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [October 6, 2020, 8:00am UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/6 "2020-10-06T08:00:33Z")

</div>

It seems to be an issue within Ansible while trying to remove namespace from received XML response.  
Please check it the PR [https://github.com/ansible-collections/ansible.netcommon/pull/152](https://github.com/ansible-collections/ansible.netcommon/pull/152) fixes the issue  
you are seeing.

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [October 6, 2020, 8:56am UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/7 "2020-10-06T08:56:08Z")

</div>

It seems to be an issue within Ansible while trying to remove the namespace from received XML response. Please check it the PR [https://github.com/ansible-collections/ansible.netcommon/pull/152](https://github.com/ansible-collections/ansible.netcommon/pull/152) fixes the issue you are seeing.

---

<div class="post-metadata">

**Author:** ![angelo\_coluni](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@angelo\_coluni](https://forum.ansible.com/u/angelo_coluni)\
**Post date:** [October 6, 2020, 11:31pm UTC](https://forum.ansible.com/t/lxml-etree-xmlsyntaxerror-using-python3-6/33940/8 "2020-10-06T23:31:24Z")

</div>

HI Ganesh,

I have verified the patch and its working, again thanks for following  
up on issue

ref : lxml.etree.XMLSyntaxError: using python3.6 (#72093)
