I believe the problem is with string formatting. In python2, it is automatically converted between a type str(which is a series of bytes) and unicodewhich is an abstract series of unicode encodings.
I assume yours filenameis of type unicode.
"tmp/%s/%s" , python unicode str . , ascii, .
return temp2 filename , .
, , . , . , decode unicode encode, . unicode (u"" "").
, tempN.