I’m fairly new to Apache as a whole, since I’ve only just started Web Developing, so please ask for more details if I haven’t provided enough.
I am using the out-of the box Apache that ships with Lion, and I have created a Python application that, every once in a while, needs to print out a UTF-8 character.
However, no matter what method I use, or how much I try, when ever I try to print out a UTF-8 character, it will throw out a 500 Internal Server Error, and I will be left with nothing.
The various things I’ve tried:
- Printing out the character directly from the Python code (With the
# -*- coding: utf-8 -*-at the top of the code.) - Printing out the character using the
.decode('utf-8')function. (Which results in printing out 3 seperate characters.) - Printing out a placeholder, and then printing out Jquery which would replace the placeholder with the Symbol (And the page throws up an Internal Server Error)
- Printing out a placeholder, and then printing out a link to a Jquery script which would replace it. (Firebug says that Firefox gets a 500 Server Error when trying to access the script.)
I cannot think of anything else.
That’s why I’ve asked here.
Any suggestions?
Thanks
~DragonXDoom
EDIT: After trying out Will’s suggestion below, I now get the following error.
<type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)
args = ('ascii', '\xe2\x80\xa2', 0, 1, 'ordinal not in range(128)')
encoding = 'ascii'
end = 1
message = ''
object = '\xe2\x80\xa2'
reason = 'ordinal not in range(128)'
start = 0
You must read http://www.joelonsoftware.com/articles/Unicode.html so that you have some understanding of the general problem.
Once you’ve understood that, then you should learn how to handle unicode correctly in Python, I think the following website should be useful, although lengthy: http://boodebr.org/main/python/all-about-python-and-unicode
Whatever you do, please do NOT skimp or skip on understanding unicode – otherwise you will continue to have subtle issues.
Furthermore, you state that you’ve attempted to use .decode(‘utf-8’) – this won’t work if python has /already/ understood the data as unicode – you want to encode it!