Characters aren't displayed correctly

John Machin sjmachin at lexicon.net
Tue Mar 3 06:54:45 EST 2009


On Mar 3, 10:22 pm, Hussein B <hubaghd... at gmail.com> wrote:
> > > Hey,
> > > I added use_unicode and charset keyword params to the connect() method
>
> > Hey, that was a brilliant idea -- I was just about to ask you to try
> >  use_unicode=True, charset="utf8" ... what were the actual values that
> > you used?
>
> I didn't supply values for them the first times.

I guessed that! I was referring to the fact that you didn't tell us
what values you did eventually supply that made it generate seemingly
reasonable Arabic letters in unicode!!  Was it charset="utf8" that did
the trick?

>
>
>
> > Let's suppose that you used charset="XXXX" ... as far as I can tell,
> > not being a mysqldb user myself, this means that your data tables and/
> > or your default connection don't use XXXX as an encoding. If so, this
> > might be an issue you might like to take up with whoever created the
> > database that you are using.
>
> > > and I got the following:
> > > u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639
> > > \u0634\u0647\u0631'
> > > So characters are getting converted successfully.
>
> > I guess so -- U+06nn sure are Arabic characters :-)
>
> > However as suggested above, "converted from what?" might be worth
> > pursuing if you like to understand what is going on instead of just
> > applying magic recipes ;-)
>
> > > Well, using the previous recipe for sending the mail:http://code.activestate.com/recipes/473810/
> > > I got the following error:
>
> > > Traceback (most recent call last):
> > >   File "HtmlMail.py", line 52, in <module>
> > >     s.sendmail(sender, receiver , msg.as_string())
>
> > [big snip]
>
> > > _handle_text
> > >     self._fp.write(payload)
> > > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> > > 115-118: ordinal not in range(128)
>
> > > Again, any ideas guys? :)
>
> > That recipe appears to have been written by an ascii bigot for ascii
> > bigots :-(
>
> > Try reading the docs for email.charset (that's the charset module in
> > the email package).
>
> Every thing is working now, I did the following:
> t = MIMEText(markup.encode('utf-8'), 'html', 'utf-8')

> Thank you all guys and especially you John, I owe you a HUGE bottle of
> beer :D

Thanks for the kind thought, but beer decreases grey-cell count and
increases girth ... I don't need any assistance with those matters :-)

Cheers,
John



More information about the Python-list mailing list