Characters aren't displayed correctly

Philip Semanchuk philip at
Sun Mar 1 15:51:23 CET 2009

On Mar 1, 2009, at 8:31 AM, Hussein B wrote:

> Hey,
> I'm retrieving records from MySQL database that contains non english
> characters.
> Then I create a String that contains HTML markup and column values
> from the previous result set.
> +++++
> markup = u'''<table>.....'''
> for row in rows:
>     markup = markup + '<tr><td>' + row['id']
> markup = markup + '</table>
> +++++
> Then I'm sending the email according to this tip:
> Well, the email contains ????? characters for each non english ones.
> Any ideas?

There's so many places where this could go wrong and you haven't  
narrowed down the problem.

Are the characters stored in the database correctly?

Are they stored consistently (i.e. all using the same encoding, not  
some using utf-8 and others using iso-8859-1)?

What are you getting out of the database? Is it being converted to  
Unicode correctly, or at all?

Are you sure that the program you're using to view the email  
understands the encoding?

Isolate those questions one at a time. Add some debugging breakpoints.  
Ensure that you have what you think you have. You might not fix your  
problem, but you will make it much smaller and more specific.

Good luck

More information about the Python-list mailing list