diff --git a/src/anyconfig/backend/xml.py b/src/anyconfig/backend/xml.py
index <HASH>..<HASH> 100644
--- a/src/anyconfig/backend/xml.py
+++ b/src/anyconfig/backend/xml.py
@@ -452,7 +452,8 @@ def etree_write(tree, stream):
     :param tree: XML ElementTree object
     :param stream: File or file-like object can write to
     """
-    tree.write(stream, encoding='UTF-8', xml_declaration=True)
+    enc = "unicode" if anyconfig.compat.IS_PYTHON_3 else "utf-8"
+    tree.write(stream, encoding=enc, xml_declaration=True)
 
 
 class Parser(anyconfig.backend.base.Parser,
fix: correct encoding arg for xml.etree.ElementTree.write

correct encoding arg for xml.etree.ElementTree.write in python 3 to
avoid the following exception raised on dump:

  TypeError: write() argument must be str, not bytes