Re: Encoding problem (Postgres)

2016-03-06 Thread Georges H
OK thanks for this informations.

Yes I would like P3, but it is my host, for the moment.

Cordially

Le dimanche 6 mars 2016 20:30:14 UTC+1, luisza14 a écrit :
>
> The problem is in your __str__() function, because Python 2 use 
> __unicode__() instead of str to return Unicode string. By default p2 return 
> bytes in __str__ and p3 return Unicode.
>
> python_2_unicode_compatible works and I thing it is the best approach 
> because you are support both version 3/2 .
>
> I recommend use Python 3 because has less problems with non-ascii 
> characters, but p2 it's OK too.
>
>
>
> El domingo, 6 de marzo de 2016, Georges H  > escribió:
> > OK thanks
> > Without the python_2_unicode_compatible decorator before my class, it 
> does not work.
> >
> > Le dimanche 6 mars 2016 14:11:41 UTC+1, Vijay Khemlani a écrit :
> >>
> >> Do you know why you had the problem in the first place or are you just 
> copy-pasting code?
> >> If you only need to support one version of Python (either 2.x or 3.x) 
> there is no need to use the python_2_unicode_compatible decorator
> >> On Sun, Mar 6, 2016 at 8:14 AM, Georges H  wrote:
> >>>
> >>> OK Thanks but I solved this little problem by adding at the top of my 
> models.py:
> >>> django.utils.encoding import from python_2_unicode_compatible
> >>>
> >>>
> >>> And always in models.py before each class:
> >>> @ python_2_unicode_compatible
> >>> Perfect!
> >>> Le dimanche 6 mars 2016 03:16:35 UTC+1, Vijay Khemlani a écrit :
> 
>  The error you are seeing is at the application level, not database, 
> so I don't think postgres is at fault.
>  Post the full stack trace for the error and the relevant part of your 
> code when it fails.
>  On Sat, Mar 5, 2016 at 3:28 PM, Georges H  
> wrote:
> >
> > Hi to all the Django community !
> > I started with Django. 
> > I have a small form that works pretty well, and that will store the 
> data in a Postgres database, that's fine.
> > OK, except that when I have a special character to enter (like an 
> accent, I am french), I get an error (No problem without special 
> characters):
> > 'Ascii' codec can not encode character u '\ xe9' in position 0: 
> ordinal not in range (128)
> > Yet I thought the default Django was utf8... 
> > So I tried to add in settings.py:
> > LANGUAGE_CODE = 'en-us'
> > LANG = 'UTF-8'
> > LC_ALL = 'UTF-8'
> > DEFAULT_CHARSET = 'utf-8'
> > But it does not change ...
> > I notice that if my base postgres is encoded in UTF-8 (when I do a 
> "SHOW SERVER_ENCODING"); the "client" is it in Unicode (when I do a "SHOW 
> CLIENT_ENCODING"). 
> > Is it linked?
> > I also notice that the "local" command at the root of my Django 
> project returns me:
> > LANG = en_US.UTF-8
> > LC_CTYPE = "en_US.UTF-8"
> > LC_NUMERIC = "en_US.UTF-8"
> > LC_TIME = "en_US.UTF-8"
> > LC_COLLATE = "en_US.UTF-8"
> > LC_MONETARY = "en_US.UTF-8"
> > LC_MESSAGES = "en_US.UTF-8"
> > LC_PAPER = "en_US.UTF-8"
> > Lc_name = "en_US.UTF-8"
> > LC_ADDRESS = "en_US.UTF-8"
> > LC_TELEPHONE = "en_US.UTF-8"
> > LC_MEASUREMENT = "en_US.UTF-8"
> > LC_IDENTIFICATION = "en_US.UTF-8"
> > LC_ALL =
> > With "LC_ALL" empty !!! So it is that I did not understand where to 
> put this setting...
> > How can I force Django to operate only in UTF-8? Or another approach?
> >
> > THX!
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, 
> send an email to django-users...@googlegroups.com.
> > To post to this group, send email to django...@googlegroups.com.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/bd87c68d-730a-49f6-892f-bb398ed4d1b1%40googlegroups.com
> .
> > For more options, visit https://groups.google.com/d/optout.
> 
> >>> --
> >>> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com.
> >>> To post to this group, send email to django...@googlegroups.com.
> >>> Visit this group at https://groups.google.com/group/django-users.
> >>> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b9b18216-e21f-4195-8ae3-b3cfbed70c31%40googlegroups.com
> .
> >>> For more options, visit https://groups.google.com/d/optout.
> >>
> > --
> > You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com .
> > To post to this group, send email to django...@googlegroups.com 
> .
> > Visit this group at http

Re: Encoding problem (Postgres)

2016-03-06 Thread Georges H
OK thanks

Without the python_2_unicode_compatible decorator before my class, it does 
not work.

Le dimanche 6 mars 2016 14:11:41 UTC+1, Vijay Khemlani a écrit :
>
> Do you know why you had the problem in the first place or are you just 
> copy-pasting code?
>
> If you only need to support one version of Python (either 2.x or 3.x) 
> there is no need to use the python_2_unicode_compatible decorator
>
> On Sun, Mar 6, 2016 at 8:14 AM, Georges H  > wrote:
>
>> OK Thanks but I solved this little problem by adding at the top of my 
>> models.py:
>>
>> django.utils.encoding import from python_2_unicode_compatible
>>
>>
>> And always in models.py before each class:
>>
>> @ python_2_unicode_compatible
>>
>> Perfect!
>>
>> Le dimanche 6 mars 2016 03:16:35 UTC+1, Vijay Khemlani a écrit :
>>>
>>> The error you are seeing is at the application level, not database, so I 
>>> don't think postgres is at fault.
>>>
>>> Post the full stack trace for the error and the relevant part of your 
>>> code when it fails.
>>>
>>> On Sat, Mar 5, 2016 at 3:28 PM, Georges H  wrote:
>>>
 Hi to all the Django community !

 I started with Django. 

 I have a small form that works pretty well, and that will store the 
 data in a Postgres database, that's fine.

 OK, except that when I have a special character to enter (like an 
 accent, I am french), I get an error (No problem without special 
 characters):

 'Ascii' codec can not encode character u '\ xe9' in position 0: 
 ordinal not in range (128)

 Yet I thought the default Django was utf8... 

 So I tried to add in settings.py:

 LANGUAGE_CODE = 'en-us'
 LANG = 'UTF-8'
 LC_ALL = 'UTF-8'
 DEFAULT_CHARSET = 'utf-8'

 But it does not change ...

 I notice that if my base postgres is encoded in UTF-8 (when I do a 
 "SHOW SERVER_ENCODING"); the "client" is it in Unicode (when I do a "SHOW 
 CLIENT_ENCODING"). 
 Is it linked?

 I also notice that the "local" command at the root of my Django project 
 returns me:

 LANG = en_US.UTF-8
 LC_CTYPE = "en_US.UTF-8"
 LC_NUMERIC = "en_US.UTF-8"
 LC_TIME = "en_US.UTF-8"
 LC_COLLATE = "en_US.UTF-8"
 LC_MONETARY = "en_US.UTF-8"
 LC_MESSAGES = "en_US.UTF-8"
 LC_PAPER = "en_US.UTF-8"
 Lc_name = "en_US.UTF-8"
 LC_ADDRESS = "en_US.UTF-8"
 LC_TELEPHONE = "en_US.UTF-8"
 LC_MEASUREMENT = "en_US.UTF-8"
 LC_IDENTIFICATION = "en_US.UTF-8"
 LC_ALL =

 With "LC_ALL" empty !!! So it is that I did not understand where to put 
 this setting...

 How can I force Django to operate only in UTF-8? Or another approach?

 THX!

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/bd87c68d-730a-49f6-892f-bb398ed4d1b1%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/b9b18216-e21f-4195-8ae3-b3cfbed70c31%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d17cffcc-d595-485c-8203-ad8dfaeb7412%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Encoding problem (Postgres)

2016-03-06 Thread Vijay Khemlani
Do you know why you had the problem in the first place or are you just
copy-pasting code?

If you only need to support one version of Python (either 2.x or 3.x) there
is no need to use the python_2_unicode_compatible decorator

On Sun, Mar 6, 2016 at 8:14 AM, Georges H  wrote:

> OK Thanks but I solved this little problem by adding at the top of my
> models.py:
>
> django.utils.encoding import from python_2_unicode_compatible
>
>
> And always in models.py before each class:
>
> @ python_2_unicode_compatible
>
> Perfect!
>
> Le dimanche 6 mars 2016 03:16:35 UTC+1, Vijay Khemlani a écrit :
>>
>> The error you are seeing is at the application level, not database, so I
>> don't think postgres is at fault.
>>
>> Post the full stack trace for the error and the relevant part of your
>> code when it fails.
>>
>> On Sat, Mar 5, 2016 at 3:28 PM, Georges H  wrote:
>>
>>> Hi to all the Django community !
>>>
>>> I started with Django.
>>>
>>> I have a small form that works pretty well, and that will store the data
>>> in a Postgres database, that's fine.
>>>
>>> OK, except that when I have a special character to enter (like an
>>> accent, I am french), I get an error (No problem without special
>>> characters):
>>>
>>> 'Ascii' codec can not encode character u '\ xe9' in position 0: ordinal
>>> not in range (128)
>>>
>>> Yet I thought the default Django was utf8...
>>>
>>> So I tried to add in settings.py:
>>>
>>> LANGUAGE_CODE = 'en-us'
>>> LANG = 'UTF-8'
>>> LC_ALL = 'UTF-8'
>>> DEFAULT_CHARSET = 'utf-8'
>>>
>>> But it does not change ...
>>>
>>> I notice that if my base postgres is encoded in UTF-8 (when I do a "SHOW
>>> SERVER_ENCODING"); the "client" is it in Unicode (when I do a "SHOW
>>> CLIENT_ENCODING").
>>> Is it linked?
>>>
>>> I also notice that the "local" command at the root of my Django project
>>> returns me:
>>>
>>> LANG = en_US.UTF-8
>>> LC_CTYPE = "en_US.UTF-8"
>>> LC_NUMERIC = "en_US.UTF-8"
>>> LC_TIME = "en_US.UTF-8"
>>> LC_COLLATE = "en_US.UTF-8"
>>> LC_MONETARY = "en_US.UTF-8"
>>> LC_MESSAGES = "en_US.UTF-8"
>>> LC_PAPER = "en_US.UTF-8"
>>> Lc_name = "en_US.UTF-8"
>>> LC_ADDRESS = "en_US.UTF-8"
>>> LC_TELEPHONE = "en_US.UTF-8"
>>> LC_MEASUREMENT = "en_US.UTF-8"
>>> LC_IDENTIFICATION = "en_US.UTF-8"
>>> LC_ALL =
>>>
>>> With "LC_ALL" empty !!! So it is that I did not understand where to put
>>> this setting...
>>>
>>> How can I force Django to operate only in UTF-8? Or another approach?
>>>
>>> THX!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/bd87c68d-730a-49f6-892f-bb398ed4d1b1%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b9b18216-e21f-4195-8ae3-b3cfbed70c31%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3P3jUfuHOB8t1AnJ1XyfQL%3DFGB7k_fHAXxhvFWJwh%3DTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Encoding problem (Postgres)

2016-03-06 Thread Georges H
OK Thanks but I solved this little problem by adding at the top of my 
models.py:

django.utils.encoding import from python_2_unicode_compatible


And always in models.py before each class:

@ python_2_unicode_compatible

Perfect!

Le dimanche 6 mars 2016 03:16:35 UTC+1, Vijay Khemlani a écrit :
>
> The error you are seeing is at the application level, not database, so I 
> don't think postgres is at fault.
>
> Post the full stack trace for the error and the relevant part of your code 
> when it fails.
>
> On Sat, Mar 5, 2016 at 3:28 PM, Georges H  > wrote:
>
>> Hi to all the Django community !
>>
>> I started with Django. 
>>
>> I have a small form that works pretty well, and that will store the data 
>> in a Postgres database, that's fine.
>>
>> OK, except that when I have a special character to enter (like an accent, 
>> I am french), I get an error (No problem without special characters):
>>
>> 'Ascii' codec can not encode character u '\ xe9' in position 0: ordinal 
>> not in range (128)
>>
>> Yet I thought the default Django was utf8... 
>>
>> So I tried to add in settings.py:
>>
>> LANGUAGE_CODE = 'en-us'
>> LANG = 'UTF-8'
>> LC_ALL = 'UTF-8'
>> DEFAULT_CHARSET = 'utf-8'
>>
>> But it does not change ...
>>
>> I notice that if my base postgres is encoded in UTF-8 (when I do a "SHOW 
>> SERVER_ENCODING"); the "client" is it in Unicode (when I do a "SHOW 
>> CLIENT_ENCODING"). 
>> Is it linked?
>>
>> I also notice that the "local" command at the root of my Django project 
>> returns me:
>>
>> LANG = en_US.UTF-8
>> LC_CTYPE = "en_US.UTF-8"
>> LC_NUMERIC = "en_US.UTF-8"
>> LC_TIME = "en_US.UTF-8"
>> LC_COLLATE = "en_US.UTF-8"
>> LC_MONETARY = "en_US.UTF-8"
>> LC_MESSAGES = "en_US.UTF-8"
>> LC_PAPER = "en_US.UTF-8"
>> Lc_name = "en_US.UTF-8"
>> LC_ADDRESS = "en_US.UTF-8"
>> LC_TELEPHONE = "en_US.UTF-8"
>> LC_MEASUREMENT = "en_US.UTF-8"
>> LC_IDENTIFICATION = "en_US.UTF-8"
>> LC_ALL =
>>
>> With "LC_ALL" empty !!! So it is that I did not understand where to put 
>> this setting...
>>
>> How can I force Django to operate only in UTF-8? Or another approach?
>>
>> THX!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bd87c68d-730a-49f6-892f-bb398ed4d1b1%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b9b18216-e21f-4195-8ae3-b3cfbed70c31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Encoding problem (Postgres)

2016-03-05 Thread Vijay Khemlani
The error you are seeing is at the application level, not database, so I
don't think postgres is at fault.

Post the full stack trace for the error and the relevant part of your code
when it fails.

On Sat, Mar 5, 2016 at 3:28 PM, Georges H  wrote:

> Hi to all the Django community !
>
> I started with Django.
>
> I have a small form that works pretty well, and that will store the data
> in a Postgres database, that's fine.
>
> OK, except that when I have a special character to enter (like an accent,
> I am french), I get an error (No problem without special characters):
>
> 'Ascii' codec can not encode character u '\ xe9' in position 0: ordinal
> not in range (128)
>
> Yet I thought the default Django was utf8...
>
> So I tried to add in settings.py:
>
> LANGUAGE_CODE = 'en-us'
> LANG = 'UTF-8'
> LC_ALL = 'UTF-8'
> DEFAULT_CHARSET = 'utf-8'
>
> But it does not change ...
>
> I notice that if my base postgres is encoded in UTF-8 (when I do a "SHOW
> SERVER_ENCODING"); the "client" is it in Unicode (when I do a "SHOW
> CLIENT_ENCODING").
> Is it linked?
>
> I also notice that the "local" command at the root of my Django project
> returns me:
>
> LANG = en_US.UTF-8
> LC_CTYPE = "en_US.UTF-8"
> LC_NUMERIC = "en_US.UTF-8"
> LC_TIME = "en_US.UTF-8"
> LC_COLLATE = "en_US.UTF-8"
> LC_MONETARY = "en_US.UTF-8"
> LC_MESSAGES = "en_US.UTF-8"
> LC_PAPER = "en_US.UTF-8"
> Lc_name = "en_US.UTF-8"
> LC_ADDRESS = "en_US.UTF-8"
> LC_TELEPHONE = "en_US.UTF-8"
> LC_MEASUREMENT = "en_US.UTF-8"
> LC_IDENTIFICATION = "en_US.UTF-8"
> LC_ALL =
>
> With "LC_ALL" empty !!! So it is that I did not understand where to put
> this setting...
>
> How can I force Django to operate only in UTF-8? Or another approach?
>
> THX!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bd87c68d-730a-49f6-892f-bb398ed4d1b1%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0FicArvKkwgfCFx-sZRkmTCfSTg8iayZjNCQeJ5xGSxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: encoding problem

2009-07-31 Thread cootetom

You could try file_name.decode('utf-8', 'replace') which will tell the
encoder not to throw errors but for any character it can't encode it
will replace with a ?



On Jul 31, 12:26 pm, alecs  wrote:
> Environment:
>
> Request Method: GET
> Request 
> URL:http://172.16.23.33/file/4719e0bdedaa4f741f032991894d52ecb08c3476a598...
> Django Version: 1.0.3
> Python Version: 2.6.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'filez.filezupload',
>  'debug_toolbar']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/usr/share/python-support/python-django/django/core/handlers/
> base.py" in get_response
>   91.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/usr/share/python-support/python-django/django/contrib/auth/
> decorators.py" in __call__
>   78.             return self.view_func(request, *args, **kwargs)
> File "/var/www/filez/filezupload/views.py" in send_file
>   253.         content_disp = u'attachment; filename="%s" ' %
> upfile.file_name
>
> Exception Type: UnicodeDecodeError at /file/
> 4719e0bdedaa4f741f032991894d52ecb08c3476a598504fd1fee92d
> Exception Value: ('ascii', '\xd0\x9d
> \xd0\xb0\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb9\xd0\xba\xd0\xb0
> \xd0\xbf\xd0\xbe\xd1\x87\xd1\x82\xd1\x8b.doc', 0, 1, 'ordinal not in
> range(128)')
>
> If I do upfile.file_name.decode('utf8').encode('cp1251') it works in
> IE ...
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: encoding problem

2009-07-31 Thread alecs

Environment:

Request Method: GET
Request URL: 
http://172.16.23.33/file/4719e0bdedaa4f741f032991894d52ecb08c3476a598504fd1fee92d
Django Version: 1.0.3
Python Version: 2.6.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'filez.filezupload',
 'debug_toolbar']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/share/python-support/python-django/django/core/handlers/
base.py" in get_response
  91. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/share/python-support/python-django/django/contrib/auth/
decorators.py" in __call__
  78. return self.view_func(request, *args, **kwargs)
File "/var/www/filez/filezupload/views.py" in send_file
  253. content_disp = u'attachment; filename="%s" ' %
upfile.file_name

Exception Type: UnicodeDecodeError at /file/
4719e0bdedaa4f741f032991894d52ecb08c3476a598504fd1fee92d
Exception Value: ('ascii', '\xd0\x9d
\xd0\xb0\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb9\xd0\xba\xd0\xb0
\xd0\xbf\xd0\xbe\xd1\x87\xd1\x82\xd1\x8b.doc', 0, 1, 'ordinal not in
range(128)')


If I do upfile.file_name.decode('utf8').encode('cp1251') it works in
IE ...
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: encoding problem

2009-07-31 Thread Daniel Roseman

On Jul 31, 11:55 am, alecs  wrote:
> I'm sending a file to user:
>
> upfile = UpFile.objects.get(file_hash=request.path[6:])
>         user = get_object_or_404(User, username=request.user.username)
>         down_file_log = DownFile.objects.create(user_id=user,
> file_id=upfile)
>         wrapper = FileWrapper(file(upfile.file_path))
>         response = HttpResponse(wrapper)
>         response['Content-Length'] = os.path.getsize(upfile.file_path)
>         response['Content-Type'] = upfile.file_content_type + ';
> charset=utf8'
>         response['Content-Disposition'] = 'attachment; filename=\"' +
> upfile.file_name + '\"'
>         return response
>
> Mysql database encoding is utf8_bin.
> The problem is in the filename: everything works OK with English, but
> if the file_name is in Russian then in IE6 it's horrible and unreadable
> (when you press on file link and download window appears) :(( But in
> Firefox && Opera it's OK :((
> Any suggestions ?

This *might* work:
 content_disp = u'attachment; filename="%s" ' % upfile.file_name
 response['Content-Disposition'] = content_disp.encode('utf-8')
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-04 Thread Malcolm Tredinnick

On Sun, 2007-11-04 at 10:54 +, omat wrote:
> I change one thing at a time when debugging but after posting here, I
> go on with experimenting. And when I respond to a request, like
> posting the traceback, usually it is not the very exact instance that
> I am running currently. 

Well, there's a problem right there. If the code you are posting here is
not the same code you are using to create the traceback, there are going
to be (possibly important differences). I now have little confidence
that what you're showing us matches the real problem. Construct the
smallest example possible that shows the issue so that people can repeat
it. That's the usual procedure. You said your data had type unicode, but
it looks like (below) it's actually a bytestring, for example. The
differences are very important in cases like this.

You might want to try subversion trunk, since I added extra debugging to
smart_unicode and force_unicode so that they show the data you pass in
and it's type as part of the output. Maybe that will give you more
information.

> I change it to be consistent with the on going
> discussion, but sometimes there are some portions that are not
> matched. But they have the same nature of problem.
> 
> In our case, the message and the subject have the same problem and
> generated almost identical tracebacks, when instance.name contains non-
> ascii chars.
> 
> And here is my Tag model:
> 
> class Tag(models.Model):
> name = models.CharField(max_length=50,
> db_index=True,
> validator_list=[isTag])
> slug = models.SlugField(editable = False,
> unique = True)
> ignore = models.BooleanField(default=False)
> synonym_for = models.ForeignKey('self', blank=True, null=True)
> 
> objects = TagManager()
> 
> def save(self):
> self.slug = slugify(self.name)
> super(Tag, self).save()
> 
> def __unicode__(self):
> name = self.name
> if self.ignore:
> name = u'%s (x)' % (name)
> if self.synonym_for:
> name = u'%s => %s' % (name, self.synonym_for.name)
> return name
> 

I don't see how you're getting this problem with self.name being a
Unicode object, so let's confirm that. In fact, it looks a lot like
self.name would be a bytestring -- that would certainly explain the
UnicodeDecodeError, because you cannot substitute non-ASCII bytestrings
into a u'%s' format string.

If 'name' is a bytestring (or if self.synonym_for.name is a bytestring),
you'll need to manually call force_unicode() on them before trying to
substitute them into the u'%s => %s' bit.

Anyway, good luck with your problem, but until the code you are showing
can be used to repeat the problem and isn't a variation that you have
changed without knowing what is significant, I cannot help any further.

Malcolm

-- 
If at first you don't succeed, destroy all evidence that you tried. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-04 Thread omat

I change one thing at a time when debugging but after posting here, I
go on with experimenting. And when I respond to a request, like
posting the traceback, usually it is not the very exact instance that
I am running currently. I change it to be consistent with the on going
discussion, but sometimes there are some portions that are not
matched. But they have the same nature of problem.

In our case, the message and the subject have the same problem and
generated almost identical tracebacks, when instance.name contains non-
ascii chars.

And here is my Tag model:

class Tag(models.Model):
name = models.CharField(max_length=50,
db_index=True,
validator_list=[isTag])
slug = models.SlugField(editable = False,
unique = True)
ignore = models.BooleanField(default=False)
synonym_for = models.ForeignKey('self', blank=True, null=True)

objects = TagManager()

def save(self):
self.slug = slugify(self.name)
super(Tag, self).save()

def __unicode__(self):
name = self.name
if self.ignore:
name = u'%s (x)' % (name)
if self.synonym_for:
name = u'%s => %s' % (name, self.synonym_for.name)
return name


Thanks...


On 4 Kasım, 02:26, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sat, 2007-11-03 at 13:13 +, omat wrote:
> > Here is the traceback:
>
> > Traceback (most recent call last):
> >   File "update_feeds.py", line 171, in process_feed
> > process_entry(entry, fpf, feed, postdict)
> >   File "update_feeds.py", line 119, in process_entry
> > feed.tags))
> >   File "/srv/django/common/tagging/managers.py", line 39, in
> > update_tags
> > tag = self.create(name = tag_name, slug = tag_slug)
> >   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> > manager.py", line 75, in create
> > return self.get_query_set().create(**kwargs)
> >   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> > query.py", line 273, in create
> > obj.save()
> >   File "/srv/django/common/tagging/models.py", line 35, in save
> > super(Tag, self).save()
> >   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> > base.py", line 271, in save
> > instance=self, created=(not record_exists))
> >   File "/usr/local/lib/python2.5/site-packages/django/dispatch/
> > dispatcher.py", line 360, in send
> > **named
> >   File "/usr/local/lib/python2.5/site-packages/django/dispatch/
> > robustapply.py", line 47, in robustApply
> > return receiver(*arguments, **named)
> >   File "/srv/django/sites/haberrobotu/aggregator/models.py", line 199,
> > in mail_new_tag
> > msg = t.render(c)
> >   File "/usr/local/lib/python2.5/site-packages/django/template/
> > __init__.py", line 174, in render
> > return self.nodelist.render(context)
> >   File "/usr/local/lib/python2.5/site-packages/django/template/
> > __init__.py", line 795, in render
> > return ''.join([force_unicode(b) for b in bits])
> >   File "/usr/local/lib/python2.5/site-packages/django/utils/
> > encoding.py", line 38, in force_unicode
> > s = unicode(s)
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position
> > 3: ordinal not in range(128)
>
> I need to improve the error handling in force_unicode() so it starts
> displaying what bogus data people passed into it. It's kind of the
> underlying solution to #5640. I might look at that when I want a break
> from other work today.
>
> Malcolm
>
> --
> The only substitute for good manners is fast 
> reflexes.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread Malcolm Tredinnick

On Sat, 2007-11-03 at 13:13 +, omat wrote:
> Here is the traceback:
> 
> Traceback (most recent call last):
>   File "update_feeds.py", line 171, in process_feed
> process_entry(entry, fpf, feed, postdict)
>   File "update_feeds.py", line 119, in process_entry
> feed.tags))
>   File "/srv/django/common/tagging/managers.py", line 39, in
> update_tags
> tag = self.create(name = tag_name, slug = tag_slug)
>   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> manager.py", line 75, in create
> return self.get_query_set().create(**kwargs)
>   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> query.py", line 273, in create
> obj.save()
>   File "/srv/django/common/tagging/models.py", line 35, in save
> super(Tag, self).save()
>   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> base.py", line 271, in save
> instance=self, created=(not record_exists))
>   File "/usr/local/lib/python2.5/site-packages/django/dispatch/
> dispatcher.py", line 360, in send
> **named
>   File "/usr/local/lib/python2.5/site-packages/django/dispatch/
> robustapply.py", line 47, in robustApply
> return receiver(*arguments, **named)
>   File "/srv/django/sites/haberrobotu/aggregator/models.py", line 199,
> in mail_new_tag
> msg = t.render(c)
>   File "/usr/local/lib/python2.5/site-packages/django/template/
> __init__.py", line 174, in render
> return self.nodelist.render(context)
>   File "/usr/local/lib/python2.5/site-packages/django/template/
> __init__.py", line 795, in render
> return ''.join([force_unicode(b) for b in bits])
>   File "/usr/local/lib/python2.5/site-packages/django/utils/
> encoding.py", line 38, in force_unicode
> s = unicode(s)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position
> 3: ordinal not in range(128)

I need to improve the error handling in force_unicode() so it starts
displaying what bogus data people passed into it. It's kind of the
underlying solution to #5640. I might look at that when I want a break
from other work today.

Malcolm

-- 
The only substitute for good manners is fast reflexes. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread Malcolm Tredinnick

On Sat, 2007-11-03 at 14:51 +, omat wrote:
> I have experimented both with the subject and the message. They both
> expose the same problem when the name contains non-ascii chars.
> 
> As a hack, I started using the slug field instead of the name field
> both in the message template and the subject and it works fine, but
> the problem is still there.

When debugging change *one* thing at a time, not multiple things! Since
the error is in the template rendering, only change that.

This is why I wanted to see the traceback, so we could see what was
really causing the problem. You said it was the subject line, but it
turns out not to be the case. So leave the subject line along and focus
your attention on the template code. It's only going to make things more
confusing for you (and us) if you keep tweaking portions that are
unrelated to the problem without first proving they are actually
relevant.

malcolm

-- 
Why can't you be a non-conformist like everyone else? 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread RajeshD

Take a look at your Tag model's __unicode__ method (or paste your Tag
model here). I suspect that's where the problem is.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread Karen Tracey
On 11/3/07, omat <[EMAIL PROTECTED]> wrote:

> "repr(sbj)"= str: u'new tag: Arkada\u015flar\u0131n'


The str: prefix on that looks a little odd.  I'm also confused how you got
repr(sbj) if (as according to the traceback) the exception occurs on the
line preceding the assignment of sbj?

What exactly is instance.name?  I had assumed name was a CharField in your
model, but the exception is occurring in force_unicode on a line where it
has been determined the input is not a basetring type, and I wouldn't think
you would ever get there if name is a CharField.  Where the exception occurs
also seems to contradict isinstance(instance.name, unicode) returning True,
which you say it does, so all in all I am confused.  I thought maybe there
was something else in your template that triggered the error, but the only
variables you access are instance.name and instance.id, plus if you replace
using name with slug the problem goes away, so I'm back to wondering what
exactly name is?

Can you trigger the error with debug on and then In the interactive
traceback look at the value of s under the line:

  s = unicode(s)

? That might provide a clue.

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread omat

I have experimented both with the subject and the message. They both
expose the same problem when the name contains non-ascii chars.

As a hack, I started using the slug field instead of the name field
both in the message template and the subject and it works fine, but
the problem is still there.

Btw, there is not much about the template:

New tag: {{ tag.name }}
Manage: http://haberrobotu.com/admin/tagging/tag/{{ tag.id }}/


Thanks...



On 3 Kasım, 16:22, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On 11/3/07, omat <[EMAIL PROTECTED]> wrote:
>
>
>
> > Here is the traceback:
>
> [snip]
>
> So, it is during the rendering of the template that things go kerflooey:
>
>   File "/srv/django/sites/haberrobotu/aggregator/models.py", line 199,
>
> > in mail_new_tag
> > msg = t.render(c)
>
>  ...in which case the contents of you template file 'app/new_tag_email.txt'
> could be enlightening.
>
> Karen


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread Karen Tracey
On 11/3/07, omat <[EMAIL PROTECTED]> wrote:
>
>
> Here is the traceback:


[snip]

So, it is during the rendering of the template that things go kerflooey:

  File "/srv/django/sites/haberrobotu/aggregator/models.py", line 199,
> in mail_new_tag
> msg = t.render(c)


 ...in which case the contents of you template file 'app/new_tag_email.txt'
could be enlightening.

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread omat

Typo: "str" in "isinstance(str, unicode)" should be "sbj"



On 3 Kasım, 15:13, omat <[EMAIL PROTECTED]> wrote:
> Here is the traceback:
>
> Traceback (most recent call last):
>   File "update_feeds.py", line 171, in process_feed
> process_entry(entry, fpf, feed, postdict)
>   File "update_feeds.py", line 119, in process_entry
> feed.tags))
>   File "/srv/django/common/tagging/managers.py", line 39, in
> update_tags
> tag = self.create(name = tag_name, slug = tag_slug)
>   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> manager.py", line 75, in create
> return self.get_query_set().create(**kwargs)
>   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> query.py", line 273, in create
> obj.save()
>   File "/srv/django/common/tagging/models.py", line 35, in save
> super(Tag, self).save()
>   File "/usr/local/lib/python2.5/site-packages/django/db/models/
> base.py", line 271, in save
> instance=self, created=(not record_exists))
>   File "/usr/local/lib/python2.5/site-packages/django/dispatch/
> dispatcher.py", line 360, in send
> **named
>   File "/usr/local/lib/python2.5/site-packages/django/dispatch/
> robustapply.py", line 47, in robustApply
> return receiver(*arguments, **named)
>   File "/srv/django/sites/haberrobotu/aggregator/models.py", line 199,
> in mail_new_tag
> msg = t.render(c)
>   File "/usr/local/lib/python2.5/site-packages/django/template/
> __init__.py", line 174, in render
> return self.nodelist.render(context)
>   File "/usr/local/lib/python2.5/site-packages/django/template/
> __init__.py", line 795, in render
> return ''.join([force_unicode(b) for b in bits])
>   File "/usr/local/lib/python2.5/site-packages/django/utils/
> encoding.py", line 38, in force_unicode
> s = unicode(s)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position
> 3: ordinal not in range(128)
>
> "repr(sbj)"= str: u'new tag: Arkada\u015flar\u0131n'
>
> isinstance(instance.name, unicode), isinstance(str, unicode) and
> isinstance(msg, unicode)  all return True.
>
> Thanks...
>
> On 3 Kasım, 14:04, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > On Sat, 2007-11-03 at 07:01 -0500, James Bennett wrote:
> > > On 11/3/07, omat <[EMAIL PROTECTED]> wrote:
> > > > sbj = u'new tag: %s' % (instance.name)
>
> > > You might want to read this:
>
> > >http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsT...
>
> > > There's a warning about using this style of string interpolation under
> > > Python 2.3 which may be relevant to your situation.
>
> > That shouldn't be an issue here. The instance.name attribute will
> > (should, at least) be a normal Python unicode string.
>
> > Malcolm
>
> > --
> > Remember that you are unique. Just like everyone 
> > else.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread omat

Here is the traceback:

Traceback (most recent call last):
  File "update_feeds.py", line 171, in process_feed
process_entry(entry, fpf, feed, postdict)
  File "update_feeds.py", line 119, in process_entry
feed.tags))
  File "/srv/django/common/tagging/managers.py", line 39, in
update_tags
tag = self.create(name = tag_name, slug = tag_slug)
  File "/usr/local/lib/python2.5/site-packages/django/db/models/
manager.py", line 75, in create
return self.get_query_set().create(**kwargs)
  File "/usr/local/lib/python2.5/site-packages/django/db/models/
query.py", line 273, in create
obj.save()
  File "/srv/django/common/tagging/models.py", line 35, in save
super(Tag, self).save()
  File "/usr/local/lib/python2.5/site-packages/django/db/models/
base.py", line 271, in save
instance=self, created=(not record_exists))
  File "/usr/local/lib/python2.5/site-packages/django/dispatch/
dispatcher.py", line 360, in send
**named
  File "/usr/local/lib/python2.5/site-packages/django/dispatch/
robustapply.py", line 47, in robustApply
return receiver(*arguments, **named)
  File "/srv/django/sites/haberrobotu/aggregator/models.py", line 199,
in mail_new_tag
msg = t.render(c)
  File "/usr/local/lib/python2.5/site-packages/django/template/
__init__.py", line 174, in render
return self.nodelist.render(context)
  File "/usr/local/lib/python2.5/site-packages/django/template/
__init__.py", line 795, in render
return ''.join([force_unicode(b) for b in bits])
  File "/usr/local/lib/python2.5/site-packages/django/utils/
encoding.py", line 38, in force_unicode
s = unicode(s)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position
3: ordinal not in range(128)


"repr(sbj)"= str: u'new tag: Arkada\u015flar\u0131n'

isinstance(instance.name, unicode), isinstance(str, unicode) and
isinstance(msg, unicode)  all return True.


Thanks...


On 3 Kasım, 14:04, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sat, 2007-11-03 at 07:01 -0500, James Bennett wrote:
> > On 11/3/07, omat <[EMAIL PROTECTED]> wrote:
> > > sbj = u'new tag: %s' % (instance.name)
>
> > You might want to read this:
>
> >http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsT...
>
> > There's a warning about using this style of string interpolation under
> > Python 2.3 which may be relevant to your situation.
>
> That shouldn't be an issue here. The instance.name attribute will
> (should, at least) be a normal Python unicode string.
>
> Malcolm
>
> --
> Remember that you are unique. Just like everyone 
> else.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread Malcolm Tredinnick

On Sat, 2007-11-03 at 07:01 -0500, James Bennett wrote:
> On 11/3/07, omat <[EMAIL PROTECTED]> wrote:
> > sbj = u'new tag: %s' % (instance.name)
> 
> You might want to read this:
> 
> http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsTheQuickChecklist
> 
> There's a warning about using this style of string interpolation under
> Python 2.3 which may be relevant to your situation.

That shouldn't be an issue here. The instance.name attribute will
(should, at least) be a normal Python unicode string.

Malcolm

-- 
Remember that you are unique. Just like everyone else. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread Malcolm Tredinnick

On Sat, 2007-11-03 at 11:41 +, omat wrote:
> Hi All,
> 
> I have a function that sends mail to managers every time a new tag is
> created, connected to post_save of a Tag model via dispatcher.
> 
> def mail_new_tag(instance):
> t = loader.get_template('app/new_tag_email.txt')
> c = Context({'tag': instance})
> msg = t.render(c)
> sbj = u'new tag: %s' % (instance.name)
> mail_managers(subject=sbj, message=msg)
> 
> This works fine when the instance.name is all ascii, but when it
> contains non-ascii characters, a UnicodeDecodeError is raised.
> 
> When debugging, I see that instance.name is a unicode object, but,
> "sbj" cannot be rendered.

Where is it raising the exception? Which line of code in particular. You
should be able to pass Unicode objects to the mail code (in fact, in
[1], I do just that for pretty much all the fields -- that was generated
using Django's email code).

Reading the code, I can't see anything special about mail_managers()
that would cause problems. So if you can past the full traceback that
will probably help work out what might be going on.

Also, what is repr(sbj) just before you call mail_managers()?

[1] http://www.flickr.com/photos/malcolmtredinnick/503502258/

Regards,
Malcolm


-- 
The early bird may get the worm, but the second mouse gets the cheese. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: encoding problem in instance signal / dispatcher?

2007-11-03 Thread James Bennett

On 11/3/07, omat <[EMAIL PROTECTED]> wrote:
> sbj = u'new tag: %s' % (instance.name)

You might want to read this:

http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsTheQuickChecklist

There's a warning about using this style of string interpolation under
Python 2.3 which may be relevant to your situation.

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Encoding problem in templates.

2006-06-03 Thread Ramiro Morales

Goyo,

On 6/3/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I have encountered a problem with Spanish tilde into my django
> templates.
> If I use the {% trans 'something' %} where something contains a Spanish
> tilde. I get an error which tells me:
>
> Exception Type: UnicodeDecodeError
> Exception Value:'ascii' codec can't decode byte 0xc3 in position 4:
> ordinal not in range(128)
> Exception Location: /usr/lib/python2.3/gettext.py in ugettext, line
> 342
>
> I've checked that the file encoding is Unicode('utf-8') and if I
> eliminate the internationalization tag I don't get the error and the
> page renders correctly.

I have reopened the ticket #1945 because I´m experiencing a similar problem
(es_AR here), but now I´m seeing that has been reported before. See
tickets #1715 and #170 (the comment previous to the last one of this ticket
seems to be the solution to the problem).

>
> It looks like the problem is at gettext module, how can I avoid this. I
> need to translate this site to many languages.
>
> Thanks in advance
>
> Goyo.
>

-- 
 Ramiro Morales

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---