title: Converting xml.etree.ElementTree to string raises "TypeError: argument of type 'int' is not iterable"
body: <p>I have a simple XML element created with <a href="https://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow noreferrer"><code>xml.etree.ElementTree</code></a> in Python 3.</p>
  
  <pre><code>import xml.etree.ElementTree as ElementTree
  person = ElementTree.Element("Person", Name="John", Age=18)
  </code></pre>
  
  <p>I can use <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.get" rel="nofollow noreferrer"><code>Element.get()</code></a> to access individual attributes from my element without any issues.</p>
  
  <pre><code>name = person.get("Name")
  age = person.get("Age")
  print(name + " is " + str(age) + " years old.")
  # output: "John is 18 years old"
  </code></pre>
  
  <p>However, if I try to convert my element to a string with <a href="https://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring" rel="nofollow noreferrer"><code>.tostring()</code></a>, I get an error "<em>TypeError: argument of type 'int' is not iterable</em>".</p>
  
  <pre><code>print(ElementTree.tostring(person))  # TypeError
  </code></pre>
  
  <p><strong>Why can't I use <code>.tostring()</code> on an <code>xml.etree.ElementTree.Element</code> with an integer attribute?</strong></p>
  
  <hr>
  
  <p>Full code:</p>
  
  <pre><code>import xml.etree.ElementTree as ElementTree
  
  person = ElementTree.Element("Person", Name="John", Age=18)
  print(ElementTree.tostring(person))  # TypeError
  </code></pre>
  
  <p>Full traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\svascellar\AppData\Local\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 1079, in _escape_attrib
      if "&amp;" in text:
  TypeError: argument of type 'int' is not iterable
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "C:/Users/svascellar/.PyCharmCE2017.3/config/scratches/scratch_13.py", line 3, in &lt;module&gt;
      print(ElementTree.tostring(person))
    File "C:\Users\svascellar\AppData\Local\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 1135, in tostring
      short_empty_elements=short_empty_elements)
    File "C:\Users\svascellar\AppData\Local\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 776, in write
      short_empty_elements=short_empty_elements)
    File "C:\Users\svascellar\AppData\Local\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 933, in _serialize_xml
      v = _escape_attrib(v)
    File "C:\Users\svascellar\AppData\Local\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 1102, in _escape_attrib
      _raise_serialization_error(text)
    File "C:\Users\svascellar\AppData\Local\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 1057, in _raise_serialization_error
      "cannot serialize %r (type %s)" % (text, type(text).__name__)
  TypeError: cannot serialize 18 (type int)
  </code></pre>