Wiadomość napisana w dniu 2009-07-29, o godz. 10:04, przez alecs:

> filename = smart_unicode(file.name, encoding='cp1251',
> strings_only=False, errors='strict')
>
> destination = open('%s/%s' % (dir_path, filename), 'wb+')
>
> UnicodeEncodeError ('ascii', u'1.3.1.\u0421\u043b.\u041f
> \u0435\u0440\u0435\u043d\u043e\u0441 \u043e\u0442\u043f
> \u0443\u0441\u043a\u0430.doc', 6, 8, 'ordinal not in range(128)')
>
> What to do ? Thanks!


Your file.name is unicode ubject, so no need to call smart_unicode (it  
will first try to encode unicode to bytestring with default codec then  
decode with yours). Then, if dir_path is unicode object, the pattern  
to build path should be also unicode. I cann't recall if open()  
accepts unicode objects as file names, but to be on safe side encode  
it to bytestring using codec of your filesystem encoding prior to  
passing to open(). Generally do not mix bytestrings and unicode  
objects in string interpolation because Python will try to encode/ 
decode using default codec (which is ASCII, usually) and this is not  
the thing you want.

-- 
Artificial intelligence stands no chance against natural stupidity

Jarek Zgoda, R&D, Redefine
jarek.zg...@redefine.pl


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to