"UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc4' in position 69: surrogates not allowed" with mime.file() on path from os.walk
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
file (Ubuntu) |
New
|
Undecided
|
Unassigned | ||
python3.5 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
The following script works fine on 16.04 LTS:
#!/usr/bin/python3
import magic
import os
dir = "/usr/share/
mime = magic.open(
mime.load()
for root, dirnames, filenames in os.walk(dir):
for f in filenames:
fn = os.path.join(root, f)
print("%s: %s" % (fn, mime.file(fn)))
Eg:
$ python3 /tmp/test.py
/usr/share/
/usr/share/
/usr/share/
/usr/share/
/usr/share/
/usr/share/
/usr/share/
...
(notice the last filename before the ellipsis)
But on 17.04, this happens:
$ python3 /tmp/test.py
/usr/share/
/usr/share/
/usr/share/
/usr/share/
/usr/share/
/usr/share/
Traceback (most recent call last):
File "/home/
print("%s: %s" % (fn, mime.file(fn)))
File "/usr/lib/
bi = bytes(filename, 'utf-8')
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc4' in position 69: surrogates not allowed
I'm guessing this is a change in python3 that python3-magic hasn't accounted for, but I'm not sure. Adding python3 task just in case.
description: | updated |
Your test program works in artful with python 3.6 for me; I guess something got updated to fix it but am not going to dig into why unless you really want me to...