<p>错误的路径是:</p>
<pre><code>'\xe3\x82\xaf\xe3\x83\xac\xe3\x82\xa4\xe3\x82\xb8\xe3\x83\xbc\xe3\x83\xbb\xe3\x83\x92\xe3\x83\x83\xe3\x83\x84\xef\xbc\x81'
</code></pre>
<p>我想这是你文件名的UTF8编码版本。</p>
<p>我在Windows7上创建了一个同名文件夹,并在其中放置了一个名为“abc.txt”的文件:</p>
<pre><code>>>> a = '\xe3\x82\xaf\xe3\x83\xac\xe3\x82\xa4\xe3\x82\xb8\xe3\x83\xbc\xe3\x83\xbb\xe3\x83\x92\xe3\x83\x83\xe3\x83\x84\xef\xbc\x81'
>>> os.listdir('.')
['?????\xb7???!']
>>> os.listdir(u'.') # Pass unicode to have unicode returned to you
[u'\u30af\u30ec\u30a4\u30b8\u30fc\u30fb\u30d2\u30c3\u30c4\uff01']
>>>
>>> a.decode('utf8') # UTF8 decoding your string matches the listdir output
u'\u30af\u30ec\u30a4\u30b8\u30fc\u30fb\u30d2\u30c3\u30c4\uff01'
>>> os.listdir(a.decode('utf8'))
[u'abc.txt']
</code></pre>
<p>因此,邓肯提出的<code>path.decode('utf8')</code>似乎起到了作用。</p>
<hr/>
<p><strong>更新</strong></p>
<p>我不能为您测试这个,但是我建议您在执行<code>.decode('utf8')</code>之前尝试检查路径是否包含非ascii。这有点老套。。。</p>
<pre><code>ASCII_TRANS = '_'*32 + ''.join([chr(x) for x in range(32,126)]) + '_'*130
path=path.strip()
path=path[17:] #to remove the file://localhost/ part
path=urllib.unquote(path)
if path.translate(ASCII_TRANS) != path: # Contains non-ascii
path = path.decode('utf8')
path=urllib.url2pathname(path)
</code></pre>