title: How to solve Key Error while XML File Parsing in Python
body: <p>I have the following XML file which I want to convert as a Pandas DataFrame.</p>
  <pre><code>row {'Id': '-1', 'Reputation': '1', 'CreationDate': '2009-09-28T00:00:00.000', 'DisplayName': 'Community', 'LastAccessDate': '2010-11-10T17:25:34.627', 'WebsiteUrl': 'http://meta.stackexchange.com/', 'Location': 'on the server farm', 'AboutMe': '&lt;p&gt;Hi, I\'m not really a person.&lt;/p&gt;\n\n&lt;p&gt;I\'m a background process that helps keep this site clean!&lt;/p&gt;\n\n&lt;p&gt;I do things like&lt;/p&gt;\n\n&lt;ul&gt;\n&lt;li&gt;Randomly poke old unanswered questions every hour so they get some attention&lt;/li&gt;\n&lt;li&gt;Own community questions and answers so nobody gets unnecessary reputation from them&lt;/li&gt;\n&lt;li&gt;Own downvotes on spam/evil posts that get permanently deleted&lt;/li&gt;\n&lt;li&gt;Own suggested edits from anonymous users&lt;/li&gt;\n&lt;li&gt;&lt;a href=&quot;http://meta.stackexchange.com/a/92006&quot;&gt;Remove abandoned questions&lt;/a&gt;&lt;/li&gt;\n&lt;/ul&gt;\n', 'Views': '0', 'UpVotes': '21001', 'DownVotes': '27468', 'AccountId': '-1'}
  row {'Id': '1', 'Reputation': '21228', 'CreationDate': '2009-09-28T14:35:46.490', 'DisplayName': 'Anton Geraschenko', 'LastAccessDate': '2020-05-17T06:51:32.333', 'WebsiteUrl': 'http://stacky.net', 'Location': 'Palo Alto, CA, United States', 'AboutMe': '&lt;p&gt;You can get in touch with me at geraschenko@gmail.com.&lt;/p&gt;\n', 'Views': '25360', 'UpVotes': '1052', 'DownVotes': '90', 'AccountId': '36500'}
  </code></pre>
  <p>The following code works for an almost identical XML file but when I use it for this file I get an error:</p>
  <p><strong>CODE</strong></p>
  <pre><code>users_tree = ET.parse(&quot;/content/Users.xml&quot;)
  users_root = users_tree.getroot()
  
  file_path_users = r&quot;/content/Users.xml&quot;
  dict_list_users = []
  
  for _, elem in ET.iterparse(file_path_users, events=(&quot;end&quot;,)):
      if elem.tag == &quot;row&quot;:
          dict_list_users.append({'UserId': elem.attrib['Id'],
                            'Reputation': elem.attrib['Reputation'],
                            'CreationDate': elem.attrib['CreationDate'],
                            'DisplayName': elem.attrib['DisplayName'],
                            'LastAccessDate': elem.attrib['LastAccessDate'],
                            'WebsiteUrl': elem.attrib['WebsiteUrl'],
                            'Location': elem.attrib['Location'],
                            'AboutMe': elem.attrib['AboutMe'],
                            'Views': elem.attrib['Views'],
                            'UpVotes': elem.attrib['UpVotes'],
                            'DownVotes': elem.attrib['DownVotes'],
                            'AccountId': elem.attrib['AccountId']})
  elem.clear()
  
  df_users = pd.DataFrame(dict_list_users)
  </code></pre>
  <p><strong>ERROR</strong></p>
  <pre><code>KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-18-7af87798bae8&gt; in &lt;module&gt;()
       24                           'DisplayName': elem.attrib['DisplayName'],
       25                           'LastAccessDate': elem.attrib['LastAccessDate'],
  ---&gt; 26                           'WebsiteUrl': elem.attrib['WebsiteUrl'],
       27                           'Location': elem.attrib['Location'],
       28                           'AboutMe': elem.attrib['AboutMe'],
  
  KeyError: 'WebsiteUrl'
  </code></pre>
  <p><strong>NOTE</strong>: This error occurs for all attributes after LastAccessDate, i.e., even if I remove the WebsiteUrl key, I get error for the next attribute and so on.</p>
  <p>Please provide me a way to fix this.</p>