On Dec 30, 2017, at 11:01 AM, Todd Wells <todd@wellshub.com> wrote:I found this error in the documentation (https://docs.python.org/3.7/library/xml.etree.elementtree.html and earlier versions):xml.etree.ElementTree.tostring(element, encoding="us-ascii", method="xml", *, short_empty_elements=True)Generates a string representation of an XML element, including all subelements. element is an
Elementinstance. encoding [1] is the output encoding (default is US-ASCII). Useencoding="unicode"to generate a Unicode string (otherwise, a bytestring is generated). method is either"xml","html"or"text"(default is"xml"). short_empty_elements has the same meaning as inElementTree.write(). Returns an (optionally) encoded string containing the XML data.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:Traceback (most recent call last):File "/Users/todd.wells/Dropbox/thePlatform SA/aws/lambda-ingest-proxy/modify-title-handler/test_modify_title_handler.py", line 11, in test_modify_titlemodified = handler.lambda_handler(event, None)File "/Users/todd.wells/Dropbox/thePlatform SA/aws/lambda-ingest-proxy/modify-title-handler/modify_title_handler.py", line 17, in lambda_handlerevent['body'] = ET.tostring(root, encoding='text', method='xml')File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 1135, in tostringshort_empty_elements=short_empty_elements)File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 759, in writewith _get_writer(file_or_filename, enc_lower) as write:File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 82, in __enter__return next(self.gen)File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 831, in _get_writernewline="\n")LookupError: unknown encoding: textUsing “us-ascii” instead of “text” works.