Thanks a lot for your reply Malcolm.
It's OK if I don't understand the reason of different behaviours, but
I must find a proper way of writing log files on the linux server.

I think I should have clarified some more facts about my setup.
1- On mac, django is running on dev mode, so stdout is the console. On
linux, it's mod_wsgi, so stdout is redirected to apache error log
files, on which I'm issuing a "tail -f" thorough ssh.
2- If I test the same code in the djang shell, the two boxes behave
the same.

To sum up, my main problem is error raising print statements on
production server, causing Http 500 responses, while they perfectly
work on the local box. And I can't remove the print statements due to
logging requirements.

What's the proper way of 'printing' a model object?
     print u"%s" % request.user
raises UnicodeEncodeError as I previously mentioned.

Regards,
Polat Tuzla


On Feb 17, 4:15 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Mon, 2009-02-16 at 17:55 -0800, Polat Tuzla wrote:
> > Hi,
> > I've the same django app deployed to my local mac os x and linux
> > server. I print the username in my view function to the standart
> > output:
> >     def my_view(request):
> >         print request.user
>
> > On mac it prints:
> >     İşÖ
>
> > which is what i expect. But on linux it prints:
> >     \xc4\xb0\xc5\x9f\xc3\x96
>
> I'm not quite sure why the Linux system doesn't display characters,
> although the data is correct. However, it's almost certainly terminal
> related: at some point Python has to format the result in a fashion that
> can be displayed on the terminal ("in the terminal application" would be
> a bit more appropriate to today's implementations, I guess) and your
> Linux and Mac systems don't necessarily coincide in their capabilities.
> Most Linux setups will be fine, but there are reasons why it might be
> restricted to something like, say, only ASCII (accessing via telnet or
> ssh with restricted negotiation, for example).
>
> You are asking Python to use the __str__ method on the model. Unless you
> somehow tell it that the result should be a unicode object, it will
> assume a str. Django uses the User.__unicode__ method and UTF-8 encodes
> it. The Linux output you're seeing is consistent with this: it's the
> UTF-8 encoding of the original string.
>
>
>
> > If I change my view code as:
> >     def my_view(request):
> >         print u"%s" % request.user
>
> > On mac it prints the same as before:
> >     İşÖ
>
> > But on linux it raises a UnicodeEncodeError:
> >     UnicodeEncodeError: 'ascii' codec can't encode characters in
> > position 0-2: ordinal not in range(128)
>
> This would be consistent with your terminal not supporting something
> like UTF_8 output -- or, rather, with Python thinking that the output
> has to be displayed in ASCII.
>
> Don't get too hung up on the results of print output (I realise it might
> hamper some debugging approaches, but it's the debugging approach that
> is causing the problem here, not some bigger issue). There's a big
> variable involved -- terminal encoding type -- that isn't present in
> normal code execution.
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
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