Have been working on this today and think I have narrowed it down to two separate problems.
Firstly I have characters encoded by MS Word saved into the database in there encoded form. Retrieving these back from the database is fine but when I try to use them by generating an RTF or a PDF document then they display very badly (e.g. “). Secondly when I try to email these generated documents as an attachment to an email I get a UnicodeEncodeError. Whilst I can't seem to figure out how to convert the MS Word encoded characters into something sensible I have been able to stop emails from throwing an error. The document get sent but with the odd character formatting incorrectly (e.g. “). The error is thrown only if you give the attachment a content type such as 'application/rtf'. What happens is that django send mail function will create the attachment strings ready for the email. It recognises that you have given a content type of 'application' and therefor uses pythons base64 file to get the string representation of what it expects to be a binary stream, because we said 'application'. The base64 function that is called (encodestring) uses binascii.b2a_base64, this function takes chunks of binary data and converts to ascii. In my case I have the raw RTF text in code and it contains non ascii characters. For me to call this an application and have it passed through binascii.b2a_base64 ends up meaning I'm trying to convert unicode to ascii which always breaks! The solution here was for me to give the attachment a content type of 'text/rtf'. This way the send mail function doesn't try to convert the input from binary to ascii and the email can send OK. So atleast the email is still sending. Now to try and figure out how to convert the MS Word special encoded characters to something understanding by python. On Jul 28, 7:04 pm, phoebebright <[email protected]> wrote: > Be very interested in the answer too! > > On Jul 28, 4:02 pm, cootetom <[email protected]> wrote: > > > I know why it's failing when I send it as an email. The django > > EmailMessage class will try to encode any text based attachment down > > to ascii. So any attachment containing characters out side of ascii > > can't be sent using django's EmailMessage class. > > > This doesn't really solve my problem, sort of makes it harder to see a > > way forward. > > > Someone must have a way of working with text pasted from MS Word in > > django? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---

