title: Python os.stat and unicode file names
body: <p>In my Django application, a user has uploaded a file with a unicode character in the name.</p>
  
  <p>When I'm downloading files, I'm calling :</p>
  
  <pre><code>os.path.exists(media)
  </code></pre>
  
  <p>to test that the file is there. This, in turn, seems to call</p>
  
  <pre><code>st = os.stat(path)
  </code></pre>
  
  <p>Which then blows up with the error :</p>
  
  <p>UnicodeEncodeError: 'ascii' codec can't encode character u'\xcf' in position 92: ordinal not in range(128)</p>
  
  <p>What can I do about this? Is there an option to path.exists to handle it?</p>
  
  <p>Update : Actually, all I had to do was encode the argument to exists, ie.</p>
  
  <pre><code>os.path.exists(media.encode('utf-8')
  </code></pre>
  
  <p>Thanks everyone who answered.</p>