title: Python os.walk encode character error
body: <p>I've got a function:</p>
  
  <pre><code>for root, dirs, files in os.walk(directory):
      for file in files:
          if fnmatch.fnmatch(file, '*.php*'):
              path = os.path.join(root, file)
              new = change_file_name(file)
              replace_dict[file] = new
              os.rename(root + os.sep + file, root + os.sep + new)
  </code></pre>
  
  <p>But when In some file is polish character (in this example "ż") I'm getting an error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/root/environments/whois/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
      response = self.full_dispatch_request()
    File "/root/environments/whois/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/root/environments/whois/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/root/environments/whois/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
      rv = self.dispatch_request()
    File "/root/environments/whois/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "./test.py", line 136, in wayback
      out = download_wayback(domain,data_od,data_do,timestamp)
    File "./wayback.py", line 121, in download_wayback
      for root, dirs, files in os.walk(unicode(directory)):
    File "/root/environments/whois/lib/python2.7/os.py", line 294, in walk
      for x in walk(new_path, topdown, onerror, followlinks):
    File "/root/environments/whois/lib/python2.7/os.py", line 294, in walk
      for x in walk(new_path, topdown, onerror, followlinks):
    File "/root/environments/whois/lib/python2.7/os.py", line 294, in walk
      for x in walk(new_path, topdown, onerror, followlinks):
    File "/root/environments/whois/lib/python2.7/os.py", line 294, in walk
      for x in walk(new_path, topdown, onerror, followlinks):
    File "/root/environments/whois/lib/python2.7/os.py", line 284, in walk
      if isdir(join(top, name)):
    File "/root/environments/whois/lib/python2.7/genericpath.py", line 41, in isdir
      st = os.stat(s)
  UnicodeEncodeError: 'ascii' codec can't encode character u'\u017c' in position 85: ordinal not in range(128)
  </code></pre>
  
  <p>Is there a way to fix it? I dont wanna change file names.</p>