<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Please disregard, I conflated two arguments.<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 30, 2017, at 11:01 AM, Todd Wells <<a href="mailto:todd@wellshub.com" class="">todd@wellshub.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I found this error in the documentation (<a href="https://docs.python.org/3.7/library/xml.etree.elementtree.html" class="">https://docs.python.org/3.7/library/xml.etree.elementtree.html</a> and earlier versions):</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><dt id="xml.etree.ElementTree.tostring" class=""><code class="descclassname" style="padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">xml.etree.ElementTree.</code><code class="descname" style="padding: 0px 1px; font-family: monospace, sans-serif; font-weight: bold; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">tostring</code><span class="sig-paren">(</span><em class="">element</em>, <em class="">encoding="us-ascii"</em>, <em class="">method="xml"</em>, <em class="">*</em>, <em class="">short_empty_elements=True</em><span class="sig-paren">)</span><a class="headerlink" href="https://docs.python.org/3.7/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring" title="Permalink to this definition" style="color: rgb(99, 99, 187); text-decoration: none; visibility: hidden; padding: 0px 4px;"></a></dt><dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; -webkit-hyphens: auto; text-align: justify; line-height: 20.799999237060547px;" class=""><p style="margin-top: 0px; -webkit-hyphens: auto; line-height: 22.399999618530273px; font-family: 'Lucida Grande', Arial, sans-serif;" class=""><font color="#222222" class="">Generates a string representation of an XML element, including all subelements.  </font><em style="color: rgb(34, 34, 34);" class="">element</em><font color="#222222" class=""> is an </font><a class="internal reference" href="https://docs.python.org/3.7/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element" style="color: rgb(99, 99, 187); text-decoration: none;"><code class="literal py docutils xref py-class" style="padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;">Element</span></code></a><font color="#222222" class=""> instance.  </font><em style="color: rgb(34, 34, 34);" class="">encoding</em><font color="#222222" class=""> </font><a class="footnote-reference" href="https://docs.python.org/3.7/library/xml.etree.elementtree.html#id5" id="id1" style="color: rgb(99, 99, 187); text-decoration: none;">[1]</a><font color="#222222" class=""> is the output encoding (default is US-ASCII). Use </font><code class="literal docutils" style="color: rgb(34, 34, 34); background-color: rgb(236, 240, 243); padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;">encoding="unicode"</span></code><font color="#222222" class=""> to generate a Unicode string (otherwise, a bytestring is generated). </font><em style="color: rgb(34, 34, 34);" class="">method</em><font color="#222222" class=""> is either </font><code class="literal docutils" style="color: rgb(34, 34, 34); background-color: rgb(236, 240, 243); padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;">"xml"</span></code><font color="#222222" class="">, </font><code class="literal docutils" style="color: rgb(34, 34, 34); background-color: rgb(236, 240, 243); padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;">"html"</span></code><font color="#222222" class=""> or </font><code class="literal docutils" style="background-color: rgb(236, 240, 243); padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;"><b class=""><font color="#e32400" class="">"text"</font></b></span></code><font color="#222222" class=""> (default is </font><code class="literal docutils" style="color: rgb(34, 34, 34); background-color: rgb(236, 240, 243); padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;">"xml"</span></code><font color="#222222" class="">). </font><em style="color: rgb(34, 34, 34);" class="">short_empty_elements</em><font color="#222222" class=""> has the same meaning as in </font><a class="internal reference" href="https://docs.python.org/3.7/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write" title="xml.etree.ElementTree.ElementTree.write" style="color: rgb(99, 99, 187); text-decoration: none;"><code class="literal py docutils xref py-meth" style="padding: 0px 1px; font-family: monospace, sans-serif; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;"><span class="pre" style="-webkit-hyphens: none;">ElementTree.write()</span></code></a><font color="#222222" class="">. Returns an (optionally) encoded string containing the XML data.</font></p></dd><div class="">The error here is the method value “text” is not a valid argument as the docs state. The correct value is “us-ascii”. From an error I encountered:</div></div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Traceback (most recent call last):</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "/Users/todd.wells/Dropbox/thePlatform SA/aws/lambda-ingest-proxy/modify-title-handler/test_modify_title_handler.py", line 11, in test_modify_title</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    modified = handler.lambda_handler(event, None)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "/Users/todd.wells/Dropbox/thePlatform SA/aws/lambda-ingest-proxy/modify-title-handler/modify_title_handler.py", line 17, in lambda_handler</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    event['body'] = ET.tostring(root, encoding='text', method='xml')</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 1135, in tostring</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    short_empty_elements=short_empty_elements)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 759, in write</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    with _get_writer(file_or_filename, enc_lower) as write:</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 82, in __enter__</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    return next(self.gen)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 831, in _get_writer</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    newline="\n")</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#e32400" class="">LookupError: unknown encoding: text</font></span></div></div></blockquote><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">Using “us-ascii” instead of “text” works.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>