title: Trying to insert in sqlite but getting key error - python
body: <p><strong>The Problem</strong></p>
  <p>I am trying to insert a list into sqlite but on the <strong>third iteration</strong> or loop read it gives the error: <code>KeyError: 'path'</code> which is weird because the 2 results before that are perfect.</p>
  <p>Here is what the data looks like if I <code>print(tag_dicts[0])</code> without inserting that data into sqlite:</p>
  <pre><code>{'comment': u'Fighter', 'album': u'Dead or Alive2', 'audio_offset': None, 'title': u'27 Unknown', 'track': None, 'disc_total': None, 'artist': u'Makoto Hosoi', 'track_total': None, 'channels': 2, 'genre': None, 'albumartist': u'Makoto Hosoi', 'filesize': 550450310L, 'composer': u'Makoto Hosoi', 'year': u'1999', 'duration': 332.06506666666667, 'path': '\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\27 Unknown.mp4', 'samplerate': 48000, 'bitrate': 294651.393, 'disc': None}
  {'comment': u'Fighter', 'album': u'Dead or Alive2', 'audio_offset': None, 'title': u'27 Unknown', 'track': None, 'disc_total': None, 'artist': u'Makoto Hosoi', 'track_total': None, 'channels': 2, 'genre': None, 'albumartist': u'Makoto Hosoi', 'filesize': 550450310L, 'composer': u'Makoto Hosoi', 'year': u'1999', 'duration': 332.06506666666667, 'path': '\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\28 Unknown.mp4', 'samplerate': 48000, 'bitrate': 294651.393, 'disc': None}
  {'comment': u'Fighter', 'album': u'Dead or Alive2', 'audio_offset': None, 'title': u'27 Unknown', 'track': None, 'disc_total': None, 'artist': u'Makoto Hosoi', 'track_total': None, 'channels': 2, 'genre': None, 'albumartist': u'Makoto Hosoi', 'filesize': 550450310L, 'composer': u'Makoto Hosoi', 'year': u'1999', 'duration': 332.06506666666667, 'path': '\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\Blazed Up Melpomene.mp4', 'samplerate': 48000, 'bitrate': 294651.393, 'disc': None}
  {'comment': u'Fighter', 'album': u'Dead or Alive2', 'audio_offset': None, 'title': u'27 Unknown', 'track': None, 'disc_total': None, 'artist': u'Makoto Hosoi', 'track_total': None, 'channels': 2, 'genre': None, 'albumartist': u'Makoto Hosoi', 'filesize': 550450310L, 'composer': u'Makoto Hosoi', 'year': u'1999', 'duration': 332.06506666666667, 'path': '\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\Bomb Factory - Exciter.mp4', 'samplerate': 48000, 'bitrate': 294651.393, 'disc': None}
  # there is more but I am only giving 4 results because the 3rd result is where I get the error
  </code></pre>
  <p>Here the code of my attempt of me inserting the data into sqlite:</p>
  <pre><code>def insert_track(con, table_name, track_data):
    sql = &quot;INSERT INTO tracks VALUES (?,?,?,?,?,?,?,?,?)&quot;
    cur = con.cursor()
  
    cur.execute(sql, track_data)
  
    conn.commit()
  
  conn = sqlite3.connect('musicdatabase.db')
  count = 0
  tag = ''
  tag_dicts = []
  musicpath_dict = {}
  extf = ['$RECYCLE.BIN']
  for root, dirs, files in os.walk(r'\\Vgmstation\\e\\Dreamcast\\Dead or Alive 2\\', followlinks=True):
      dirs[:] = [d for d in dirs if d not in extf]
      for name in files:
          if name.endswith(&quot;.mp4&quot;):
              musiclist=str(os.path.join(root, name))
              tag = TinyTag.get(musiclist)
              musicpath_dict = {'path': os.path.join(root,name)}
              musiccopy = musicpath_dict.copy()
              tag_dicts.append(tag.as_dict())
              tag_dicts[0].update(musicpath_dict)
              print(tag_dicts[0])
  
              for track in tag_dicts:
                  insert_track(conn, 'tracks', (track['title'], track['album'], track['comment'], track['genre'], track['artist'], track['composer'], track['year'], track['duration'], track['path']))
  
  conn.close()
  </code></pre>
  <p>But on the third, loop or iteration (the data that has the <code>\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\Blazed Up Melpomene.mp4</code> as it's path) it will give an error:</p>
  <pre><code>{'comment': u'Fighter', 'album': u'Dead or Alive2', 'audio_offset': None, 'title': u'27 Unknown', 'track': None, 'disc_total': None, 'artist': u'Makoto Hosoi', 'track_total': None, 'channels': 2, 'genre': None, 'albumartist': u'Makoto Hosoi', 'filesize': 550450310L, 'composer': u'Makoto Hosoi', 'year': u'1999', 'duration': 332.06506666666667, 'path': '\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\\\27 Unknown.mp4', 'samplerate': 48000, 'bitrate': 294651.393, 'disc': None}
  {'comment': u'Fighter', 'album': u'Dead or Alive2', 'audio_offset': None, 'title': u'27 Unknown', 'track': None, 'disc_total': None, 'artist': u'Makoto Hosoi', 'track_total': None, 'channels': 2, 'genre': None, 'albumartist': u'Makoto Hosoi', 'filesize': 550450310L, 'composer': u'Makoto Hosoi', 'year': u'1999', 'duration': 332.06506666666667, 'path': '\\\\Vgmstation\\\\e\\\\Dreamcast\\\\Dead or Alive 2\\\\28 Unknown.mp4', 'samplerate': 48000, 'bitrate': 294651.393, 'disc': None}
  
  Traceback (most recent call last):
    File &quot;\\VGMSTATION\testing scripts\search and add to sqlite.py&quot;, line 97, in &lt;module&gt;
      insert_track(conn, 'tracks', (track['title'], track['album'], track['comment'], track['genre'], track['artist'], track['composer'], track['year'], track['duration'], track['path']))
  KeyError: 'path'
  &gt;&gt;&gt; 
  </code></pre>
  <p>I may make another test script and write that third result manually into sqlite (instead of using os.walk to get the path) to see if I get the same error.</p>
  <p>I have no clue why that third result fails when the first two are fine. Any ideas are appreciated.</p>
  <p>Thank you for your time,</p>