Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
UnicodeDecodeError: 'ascii' codec inside controller
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Carlos Alberto Costa Beppler  
View profile  
 More options Nov 1 2012, 8:32 am
From: Carlos Alberto Costa Beppler <bepp...@gmail.com>
Date: Thu, 1 Nov 2012 05:32:57 -0700 (PDT)
Local: Thurs, Nov 1 2012 8:32 am
Subject: UnicodeDecodeError: 'ascii' codec inside controller

I´m having an very strange UnicodeDecodeError on the following program.

The most strange is that before start the application the same formatting
instruction works, it raises the error only inside the GET (or any other
controller method).

The test program is:
==============================
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import web

class Index(object):
    def GET(self, id = None):
        if id:
         # this raises UnicodeDecodeError
         msg = 'Não encontrado: %s' % web.ctx.path
         raise web.notfound(msg)
        return 'Encontrei'

urls = (
    '/(.*)', 'Index'
)

application = web.application(urls, globals())

# this works
msg = 'Não encontrado: %s' % '/test'
web.debug(msg)

if __name__=='__main__':
    application.run()
==============================

The log message generated on server is:
==============================
beppler@squeeze:~/site$ python test.py
'N\xc3\xa3o encontrado: /test'
http://0.0.0.0:8080/
'N\xc3\xa3o encontrado: /test'
Traceback (most recent call last):
  File "/home/beppler/Projects/elco/src/web/application.py", line 239, in
process
    return self.handle()
  File "/home/beppler/Projects/elco/src/web/application.py", line 230, in
handle
    return self._delegate(fn, self.fvars, args)
  File "/home/beppler/Projects/elco/src/web/application.py", line 462, in
_delegate
    return handle_class(cls)
  File "/home/beppler/Projects/elco/src/web/application.py", line 438, in
handle_class
    return tocall(*args)
  File "/home/beppler/Projects/elco/src/site/test.py", line 17, in GET
    msg = 'Não encontrado: %s' % web.ctx.path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
ordinal not in range(128)
==============================


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrey Kuzmin  
View profile  
 More options Nov 1 2012, 9:57 am
From: Andrey Kuzmin <Andre...@gmail.com>
Date: Thu, 1 Nov 2012 06:57:27 -0700 (PDT)
Local: Thurs, Nov 1 2012 9:57 am
Subject: Re: UnicodeDecodeError: 'ascii' codec inside controller

Have you tried marking your string as unicode?

msg = *u*'Não encontrado: %s' % web.ctx.path

On Thursday, November 1, 2012 4:32:57 PM UTC+4, Carlos Alberto Costa


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carlos Alberto Costa Beppler  
View profile  
 More options Nov 1 2012, 11:58 am
From: Carlos Alberto Costa Beppler <bepp...@gmail.com>
Date: Thu, 1 Nov 2012 08:58:40 -0700 (PDT)
Local: Thurs, Nov 1 2012 11:58 am
Subject: Re: UnicodeDecodeError: 'ascii' codec inside controller

Thanks.

It worked.

I understand that this exception happening because of the web.ctx.path is
an unicode string and the % operator is converting the "format" string to
unicode using the defatult encode. Is this right?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »