My code is very simple:
def index():
response.flash = "Hello";
form = SQLFORM(db.requests)
if form.accepts(request.vars):
response.flash = 'Thanks. We will contact you soon.'
body = ''
for var in form.vars:
body = body + var + ':\r\n' + str(form.vars[var]) + '\r\n\r
\n' #
mail.send('[email protected]', 'Requests', body)
redirect(URL(r=request,f='contacts'))
elif form.errors:
response.flash = 'Form has errors'
else:
response.flash = 'Please fill the form'
return dict(form=form)
And I enter some cyrilic characters in the form.
When I submit form I get:
mail.send(\'[email protected]\', \'subject\', body)\n File "/var/www/
web2py/gluon/tools.py", line 271, in send\n attachment.attach
(email.MIMEText.MIMEText(text.encode(encoding)))\nUnicodeDecodeError:
\'ascii\' codec can\'t decode byte 0xd0 in position 30: ordinal not
in
range(128)\n'
I used this code on top of my default controller and it helped.
I don't know why should i do this, but it really helped I got this
idea
from this page http://trac.edgewall.org/ticket/5628
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
What it changes and should I really write this code on the top of each
controller?
On Nov 30, 9:00 pm, Thadeus Burgess <[email protected]> wrote:
> The reason is because there are non-latin characters in the text body.
>
> Where are you getting your data source? Is it possible to use UTF-8 encoded
> characters instead of ASCII?
>
> Are you attempting to pass a different encoding scheme to the Mail object?
>
> Can we get some code that you are using?
>
> -Thadeus
>
>
>
> On Mon, Nov 30, 2009 at 12:50 PM, Alex <[email protected]> wrote:
> > his error happens when non-latin characters are passed in the body,
> > what is the reason and how to fix it, i'm still not very strong in
> > python errors. Thanks.
--
You received this message because you are subscribed to the Google Groups
"web2py-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/web2py?hl=en.