not enough. It all comes down to this:
>>> 'ç'.decode('ascii')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
0: ordinal not in range(128)

this is a little bit better:
>>> 'ç'.decode('ascii','ignore')
u''

(though information may be loss)

So, just to make it work, I converted all to strings using this simple
method:
def clean_enc(item):
    return str(item.decode('ascii','ignore'))

I don't want to dramatize this issue but I'm using the default mail
mechanisms of web2py to mail and there was a loss of backward
compatibility from my previous code (which is not the real problem for
me in this case) and worse than that there were possible clients that
may have been denied from establishing contact threw my form. I think
we need to correct this so that this doesn't happen again.


On Dec 9, 4:13 am, mdipierro <[email protected]> wrote:
> message=msg.decode('latin1')
>
> not
>
> message=msg.encode('latin1')
>
> are you sure?
>
> On Dec 8, 10:04 pm, blackthorne <[email protected]> wrote:
>
>
>
> > also tried .encode('ascii','ignore') without luck
>
> > On Dec 9, 3:44 am, mdipierro <[email protected]> wrote:
>
> > > Try pass:
>
> > > message=msg.decode('latin1')
>
> > > On Dec 8, 8:51 pm, blackthorne <[email protected]> wrote:
>
> > > > Thank you for your answer.
> > > > I keep having the same behavior, though.
>
> > > > Do you have ideas?
>
> > > > On Dec 9, 2:34 am, mdipierro <[email protected]> wrote:
>
> > > > > actually the bug was in the previous version. You have to specify the
> > > > > encoding
>
> > > > >     return mail.send(to=
> > > > > ['[email protected]','[email protected]'],
> > > > >     subject=about,
> > > > >     message=msg, encoding='latin1')
>
> > > > > On Dec 8, 7:05 pm, blackthorne <[email protected]> wrote:
>
> > > > > > hi
> > > > > > there seems to be a bug a in the unicode process, probably in the 
> > > > > > mail
> > > > > > () method on the most recent versions of web2py. I developed an
> > > > > > application with a contact form that works on. When I got it into
> > > > > > production, I tested it with the latest version of web2py and I got
> > > > > > Internal Server Error with the message:
>
> > > > > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> > > > > > 0: ordinal not in range(128)
>
> > > > > > def email_user(sender,msg,about="group notice"):
> > > > > >     message='Reply-to: ' + sender + '\n ' + msg
> > > > > >     return mail.send(to=
> > > > > > ['[email protected]','[email protected]'],
> > > > > >     subject=about,
> > > > > >     message=msg)
>
> > > > > > def contact():
> > > > > >     response.view = theme + '/contact.html'
> > > > > >     form=SQLFORM(db.mail,fields=
> > > > > > ['your_name','your_email','your_message'])
> > > > > >     if form.accepts(request.vars,session,dbio=False):
> > > > > >         subject='casasdocastro.com: ' + form.vars.your_name
> > > > > >         sent = email_user(sender=form.vars.your_email,
> > > > > > -->    msg=form.vars.your_message,
> > > > > >          about=subject)
> > > > > >         if sent:
> > > > > >             response.flash=T('message_submitted')
> > > > > >         else:
> > > > > >             response.flash=T('message_failed')
> > > > > >         db.mail.insert(your_name=form.vars.your_name,
> > > > > > your_email=form.vars.your_email, 
> > > > > > your_message=form.vars.your_message,
> > > > > > sent=sent)
> > > > > >     elif form.errors:
> > > > > >         response.flash=T('check_contact_form')
> > > > > >     form.custom.submit['_value']=T('send_submit')
> > > > > >     return dict(form=form,
> > > > > >                 news=getNews())
>
> > > > > > Again, this code works fine in v1.67
>
> > > > > > Thank, Best Regards

--

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.


Reply via email to