title: Postgresql and Python: Insert UTF-8 string
body: <p>I am trying to insert a list of strings into a Postgres table.</p>
  
  <p>The strings are folder names, gathered from a Windows machine, then rewritten to a unix-style string.</p>
  
  <p>This works, but when there is a foldername with "üöä" the insert does not fail, but inserts an empty string.</p>
  
  <p>Here is the code that I use to insert the values:</p>
  
  <pre><code>def db_insert_paths(paths):
      paths.sort()
      for path in paths:
          print(path)
          print(type(path))
  
          cur.execute("INSERT INTO rasp (folder) VALUES (%s)", (path,))
  
      cur.close()
      conn.close()
  
      return 0
  </code></pre>
  
  <p>Here are some examples:
  I also captured the traffic sent to the Postgres server.</p>
  
  <pre><code>/mnt/hdd/Bilder/2004/2004.08.15. Dorffest
  &lt;class 'str'&gt;
  
  INSERT INTO rasp (folder) VALUES ('/mnt/hdd/Bilder/2004/2004.08.15. Dorffest')
  </code></pre>
  
  <p>This insert works. The data is in the table.</p>
  
  <p>However, the next one doesn't:</p>
  
  <pre><code>/mnt/hdd/Bilder/2004/2004.08.30. Filterschacht räumen und reinigen
  &lt;class 'str'&gt;
  
  INSERT INTO rasp (folder) VALUES ('/mnt/hdd/Bilder/2004/2004.08.30. Filterschacht r��umen und reinigen')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ZBPr6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZBPr6.png" alt="Wireshark capture"></a></p>
  
  <p>The entry is empty.</p>
  
  <p>What am I doing wrong here? I am guessing it is some kind of encoding fail.</p>
  
  <p>I am using python3.4 on Windows 8.1, with Postgresql 9.5. The field type is "text".</p>