title: KeyError while generating an HTML page
body: <p>I'm generating an HTML page from a simple template:</p>
  
  <pre><code>&lt;div id="dateReference"&gt;
      &lt;h1 id="currentDate"&gt;Exploit automation completed on: {date_of_attack}&lt;/h1&gt;
  &lt;/div&gt;
  &lt;div id="amountOfHost"&gt;
      &lt;h4 id="hostCount"&gt;Total of {amount_of_hosts} separate hosts attacked&lt;/h4&gt;
  &lt;/div&gt;
  &lt;div id="hostDropDown" class="dropdown-content"&gt;
      {all_hosts_attacked}
  &lt;/div&gt;
  &lt;div id="successfulAttacks"&gt;
      &lt;h4 id="successAttacksBanner"&gt;Successful Attacks:&lt;/h4&gt;
  &lt;/div&gt;
  {exploit_table}
  </code></pre>
  
  <p>How I'm creating the tags is by generating a simple string using a simple class:</p>
  
  <pre><code>import os
  import datetime
  
  import lib.settings
  
  
  class HtmlPageGenerator(object):
  
      def __init__(self, successes, failures, host_count):
          self.success = successes
          self.fails = failures
          self.host_count = host_count
          self.html_template = lib.settings.HTML_PAGE_TEMPLATE
          self.attacked_hosts_list = open(lib.settings.HOST_FILE).readlines()
  
      def _generate_html_table(self, headers):
          retval = '&lt;table id="generatedExploitTable"&gt;&lt;tr&gt;'
          for header in headers:
              retval += "&lt;th&gt;{}&lt;/th&gt;".format(header)
          retval += "&lt;/tr&gt;&lt;tr&gt;"
          for value in self.success:
              retval += "&lt;td&gt;{}&lt;/td&gt;".format(value)
          retval += "&lt;/tr&gt;&lt;/table&gt;"
          return retval
  
      def _generate_drop_down_menu(self):
          retval = ""
          for host in self.attacked_hosts_list:
              retval += '&lt;a href="#"&gt;{}&lt;/a&gt;'.format(host.strip())
          return retval
  
      def generator(self):
          if not os.path.exists(lib.settings.HTML_PAGE_PATH):
              os.makedirs(lib.settings.HTML_PAGE_PATH)
          with open(self.html_template, 'r') as template, open(lib.settings.HTML_PAGE_GENERATION_FILE_PATH, 'a+') as out:
              to_format = template.read()
              out.write(
                  to_format.format(
                      date_of_attack=str(datetime.datetime.today()).split(".")[0],
                      exploit_table=self._generate_html_table(["Exploit Paths"]),
                      amount_of_hosts=self.host_count,
                      all_hosts_attacked=self._generate_drop_down_menu()
                  )
              )
          return lib.settings.HTML_PAGE_GENERATION_FILE_PATH
  </code></pre>
  
  <p>The <code>_generate_html_table</code> function is working properly, and has generated successfully, the issue is when I try to generate the <code>&lt;a href="#"</code> tags it throws the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "xxxxx.py", line 10, in &lt;module&gt;
      23
    File "/Users/admin/bin/tools/xxxxx/lib/page_generator.py", line 42, in generator
      all_hosts_attacked=self._generate_drop_down_menu()
  KeyError: '\n            document'
  </code></pre>
  
  <p>What is causing my error and how can I fix this successfully? I've attempted to generate the links as a <code>list</code> and return it joined instead but it throws the same <code>Exception</code>. Any help with this would be great</p>