title: Python etree.ElementTree IOError: [Errno 22] invalid mode ('rb') or filename -
body: <p>I am using zipfile module and whenever I try to read extracted XML data I get this error and I don't quite understand it, I've tried to resolve it by using different modes but that hasn't worked.</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\python\QuarryLang-master\core\test.py", line 18, in &lt;module&gt;
      p = load_data("ConlangExample.zip")
    File "C:\python\QuarryLang-master\core\cio.py", line 71, in load_data
      meta = ET.parse(zipdata.open('metadata.xml', 'rU').read())
    File "C:\python\App\lib\xml\etree\ElementTree.py", line 1182, in parse
      tree.parse(source, parser)
    File "C:\python\App\lib\xml\etree\ElementTree.py", line 647, in parse
      source = open(source, "rb")
  IOError: [Errno 22] invalid mode ('rb') or filename: '&lt;metadata&gt;&lt;conlang&gt;Pseudo-German&lt;/conlang&gt;&lt;author&gt;Andres&lt;/author&gt;&lt;family&gt;Germanic&lt;/family&gt;&lt;T_Type&gt;Agglulinative&lt;/T_Type
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>import zipfile
  import xml.etree.ElementTree as ET
  import os
  import conassets
  def load_configuration(filename):
      settings = ET.parse(filename)
      root = settings.getroot()
      return (root.find('appname').text, root.find('author').text, root.find('version').text)
  
  
  
  def save_data(filename, conlang, zpack=0):
      xml_metadata = ET.Element("metadata")
      xml_dictionary = ET.Element("dictionary")
      xml_dialect = ET.Element("dialects")
  
  
      #Set up metadata first
      ET.SubElement(xml_metadata, "conlang").text = conlang.Name
      ET.SubElement(xml_metadata, "author").text = conlang.Author
      ET.SubElement(xml_metadata, "family").text = conlang.Family
      ET.SubElement(xml_metadata, "T_Type").text = conlang.T_Type
      ET.SubElement(xml_metadata, "A_Type").text = conlang.A_Type
      ET.SubElement(xml_metadata, "L_Type").text = conlang.L_Type
  
      mtree = ET.ElementTree(xml_metadata)
      mtree.write("metadata.xml")
  
      #Set up dictionary
      if len(conlang.words) != 0:
              for x in conlang.words:
                  word = ET.SubElement(xml_dictionary,"word")
                  ET.SubElement(word, "word").text = x.word
                  ET.SubElement(word, "definition").text = x.definition 
                  ET.SubElement(word, "pos").text = x.pos
                  ET.SubElement(word, "register").text = x.register
                  ET.SubElement(word, "class").text = x._class
                  ET.SubElement(word, "dialect").text = x.dialect
                  ET.SubElement(word, "source lang").text = x.source_lang
                  ET.SubElement(word, "source").text = x.source
                  ET.SubElement(word, "notes").text = x.notes
  
  
              dtree = ET.ElementTree(xml_dictionary)
              dtree.write("dictionary.xml")
      if len(conlang.dialects) != 0:
          #Write dialects
          for x in conlang.dialects:
              dialect = ET.SubElement(xml_dialect, "dialect")
              ET.SubElement(dialect, "name").text = x.Name
              ET.SubElement(dialect, "description").text = x.description
  
          ditree = ET.ElementTree(xml_dialect)
          ditree.write("dialects.xml")
      if zpack == 0 or zpack == 3:
          with zipfile.ZipFile(filename, "w") as myconlang:
              myconlang.write("metadata.xml")
              myconlang.write("dictionary.xml")
              myconlang.write("dialects.xml")
              myconlang.close()
          if zpack != 3:
              os.remove('metadata.xml')
              os.remove('dictionary.xml')
              os.remove('dialects.xml')
  
  
  
  def load_data(filename):
      zipdata = zipfile.ZipFile(filename, 'r')
      meta = ET.parse(zipdata.open('metadata.xml', 'rU').read())
      dictionary = ET.parse(zipdata.open('dictionary.xml', 'rU').read())
      dialect = ET.parse(zipdata.open('dialect.xml', 'rU').read())
  
      meta_root = meta.getroot()
      dict_root = dictionary.getroot()
      dial_root = dialect.getroot()
  
      #Get metadata
      C = Conlang(meta_root.find('conlang').text, meta_root.find('author'), meta_root.find('family').text, meta_root.find('T_Type').text, meta_root.find('A_Type').text, meta_root.find('L_Type').text)
  
      #Get dictionary data
      for word in dict_root.findall('word'):
          W = Word(word.find('word').text, word.find('definition').text, word.find('ipa').text, word.find('register').text, word.find('class').text, word.find('dialect'), word.find('source_lang').text, word.find('source').text, word.find('notes').text)
          W.add2list(C)
  
      #Load all dialect data
      for dialect in dial_root.findall('dialect'):
          D = Dialect(dialect.find('name').text, dialect.find('description').text)
          D.add2list(C)
  
  
      return C
  </code></pre>