Google Groups Home
Help | Sign in
Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not _anonymous()) gives internal server error
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
  11 messages - Collapse all
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
Thomas Wittek  
View profile
 More options Oct 30 2007, 7:05 am
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Tue, 30 Oct 2007 04:05:37 -0700
Local: Tues, Oct 30 2007 7:05 am
Subject: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
Hi!

I just came across this problem.
Suppose I have this (minimal) controller:

class Root(controllers.RootController):
    @expose()
    def test(self, *args, **kwargs):
        return "bla"

    @expose()
    @identity.require(identity.not_anonymous())
    def test2(self, *args, **kwargs):
        return "bla2"

When I call `/test?a=ä`, all works as expected. But when I call the
second handler `/test2?a=ä`, I get an error:

500 Internal error

The server encountered an unexpected condition which prevented it from
fulfilling the request.

Page handler: 'ordinal not in range(128)'
Traceback (most recent call last):
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\_cphttptools.py", line 103, in _run
    applyFilters('before_main')
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\__init__.py", line 151, in applyFilters
    method()
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 31, in before_main
    self.decode(enc)
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 50, in decode
    decodedParams[key] = value.decode(enc)
  File "c:\programme\python25\lib\encodings\utf_8.py", line 16, in
decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
position 0: ordinal not in range(128)

I guess that this is not supposed to throw this error, is it?
I'm using TG 1.0.4b2.

Thanks for any advice!


    Reply to author    Forward  
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.
Florent Aide  
View profile
 More options Oct 30 2007, 10:04 am
From: "Florent Aide" <florent.a...@gmail.com>
Date: Tue, 30 Oct 2007 15:04:17 +0100
Local: Tues, Oct 30 2007 10:04 am
Subject: Re: [TurboGears] Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Oct 30, 2007 12:05 PM, Thomas Wittek <streawkc...@googlemail.com> wrote:

Good catch!

Could you create a ticket on our trac system and ping us back here.
Please try to attach some example project so we can reproduce easily
the error.

Thanks,
Florent.


    Reply to author    Forward  
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.
Thomas Wittek  
View profile
 More options Oct 30 2007, 11:06 am
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Tue, 30 Oct 2007 08:06:04 -0700
Local: Tues, Oct 30 2007 11:06 am
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Oct 30, 3:04 pm, "Florent Aide" <florent.a...@gmail.com> wrote:

> Could you create a ticket on our trac system and ping us back here.

Great, my ticket got rejected: "Submission rejected as potential spam
(Akismet says content is spam)"

Text:

==== 8< ====

Suppose I have this (minimal) controller:

{{{
class Root(controllers.RootController):
    @expose()
    def test(self, *args, **kwargs):
        return "bla"

    @expose()
    @identity.require(identity.not_anonymous())
    def test2(self, *args, **kwargs):
        return "bla2"

}}}

When I call `/test?a=ä`, all works as expected.
But when I call the second handler `/test2?a=ä`, I get an error:

{{{
500 Internal error
[..]
  File "[..]python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg
\cherrypy\filters\decodingfilter.py", line 50, in decode
    decodedParams[key] = value.decode(enc)
  File "[..]python25\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
position 0: ordinal not in range(128)

}}}

The full test project (actually, only the controllers.py has been
modified after the quickstart) is attached.

==== >8 ====

> Please try to attach some example project so we can reproduce easily
> the error.

Can be downloaded here: http://gedankenkonstrukt.de/files/tg-id-utf-bug.zip

Cheers


    Reply to author    Forward  
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.
Thomas Wittek  
View profile
 More options Oct 30 2007, 12:39 pm
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Tue, 30 Oct 2007 09:39:44 -0700
Local: Tues, Oct 30 2007 12:39 pm
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Oct 30, 12:05 pm, Thomas Wittek <streawkc...@googlemail.com> wrote:

> When I call `/test?a=ä`, all works as expected. But when I call the
> second handler `/test2?a=ä`, I get an error: [..] 500 Internal error

Found another, maybe related bug:
`/test2?a.b=b`

500 Internal error

The server encountered an unexpected condition which prevented it from
fulfilling the request.

Traceback (most recent call last):
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\_cphttptools.py", line 103, in _run
    applyFilters('before_main')
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\__init__.py", line 151, in applyFilters
    method()
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 31, in before_main
    self.decode(enc)
  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 50, in decode
    decodedParams[key] = value.decode(enc)
AttributeError: 'dict' object has no attribute 'decode'

Seems like Identity and CP are battling each other in decoding the
request params...


    Reply to author    Forward  
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.
Florent Aide  
View profile
 More options Oct 30 2007, 4:33 pm
From: "Florent Aide" <florent.a...@gmail.com>
Date: Tue, 30 Oct 2007 21:33:53 +0100
Local: Tues, Oct 30 2007 4:33 pm
Subject: Re: [TurboGears] Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Oct 30, 2007 4:06 PM, Thomas Wittek <streawkc...@googlemail.com> wrote:

> On Oct 30, 3:04 pm, "Florent Aide" <florent.a...@gmail.com> wrote:

> > Could you create a ticket on our trac system and ping us back here.

> Great, my ticket got rejected: "Submission rejected as potential spam
> (Akismet says content is spam)"

We just created the spam filtering but now we trained it a little and
also tweaked the parameters, so it should accept you ticket. Could you
try again to create it ? And sorry for the inconvenience.

Florent.


    Reply to author    Forward  
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.
Thomas Wittek  
View profile
 More options Oct 30 2007, 5:00 pm
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Tue, 30 Oct 2007 14:00:27 -0700
Local: Tues, Oct 30 2007 5:00 pm
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Oct 30, 9:33 pm, "Florent Aide" <florent.a...@gmail.com> wrote:

> On Oct 30, 2007 4:06 PM, Thomas Wittek <streawkc...@googlemail.com> wrote:
> > Great, my ticket got rejected: "Submission rejected as potential spam
> > (Akismet says content is spam)"

> We just created the spam filtering but now we trained it a little and
> also tweaked the parameters, so it should accept you ticket. Could you
> try again to create it ? And sorry for the inconvenience.

Ok, works.
Filed as #1598 under http://trac.turbogears.org/ticket/1598

    Reply to author    Forward  
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.
Adi  
View profile
 More options Nov 15 2007, 5:19 am
From: Adi <fanet...@gmail.com>
Date: Thu, 15 Nov 2007 02:19:20 -0800 (PST)
Local: Thurs, Nov 15 2007 5:19 am
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
Hi

Struggling with the same error, here's the workaround I found
that seems to be working for me. I'm using TG 1.0.2.2

IN turbogears\visit\api.py
  IN class VisitFilter(BaseFilter):
    IN def before_main(self):

adding at the end of before_main (line 165 for TG 1.0.0.2):

for k,v in cherrypy.request.params.iteritems():
    cherrypy.request.params[k]=v.encode('utf-8')

seems to do the job. However as I'm not using the latest TG version
and I'm not too confident with all this I'd rather let the
knowleadgeable team check whether this is ok or not! My 2 cents...


    Reply to author    Forward  
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.
Thomas Wittek  
View profile
 More options Nov 15 2007, 8:30 am
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Thu, 15 Nov 2007 05:30:26 -0800 (PST)
Local: Thurs, Nov 15 2007 8:30 am
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Nov 15, 11:19 am, Adi <fanet...@gmail.com> wrote:

> IN turbogears\visit\api.py
>   IN class VisitFilter(BaseFilter):
>     IN def before_main(self):

> adding at the end of before_main (line 165 for TG 1.0.0.2):

> for k,v in cherrypy.request.params.iteritems():
>     cherrypy.request.params[k]=v.encode('utf-8')

Doesn't work for me (TG 1.0.4b2).
Maybe I inserted the code at the wrong position?
I added it before:

        try:
            for plugin in _plugins:
                plugin.record_request(visit)


    Reply to author    Forward  
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.
Adi  
View profile
 More options Nov 16 2007, 4:38 am
From: Adi <fanet...@gmail.com>
Date: Fri, 16 Nov 2007 01:38:44 -0800 (PST)
Local: Fri, Nov 16 2007 4:38 am
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
Here's where I have put the 2 extra lines: at the end of the method:

        # Inform all the plugins that a request has been made for the
current
        # visit. This gives plugins the opportunity to track click-
path or
        # retrieve the visitor's identity.
        try:
            for plugin in _plugins:
                plugin.record_request( visit )
        except cherrypy.InternalRedirect, e:
            # Can't allow an InternalRedirect here because CherryPy is
dumb,
            # instead change cherrypy.request.object_path to the url
desired.
            cherrypy.request.object_path= e.path

        for k,v in cherrypy.request.params.iteritems():
            cherrypy.request.params[k]=v.encode('utf-8')

By the way In my case I'm not decorating a method by using
@identity.require(identity.not_anonymous()) but using
require = identity.in_group("mygroup") at the start of a
SecureResource controller class.But I did have te same kind of error
before modifying turbogears\visit\api.py


    Reply to author    Forward  
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.
Thomas Wittek  
View profile
 More options Nov 18 2007, 4:58 am
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Sun, 18 Nov 2007 01:58:59 -0800 (PST)
Local: Sun, Nov 18 2007 4:58 am
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Nov 16, 10:38 am, Adi <fanet...@gmail.com> wrote:

> Here's where I have put the 2 extra lines: at the end of the method:

Oh, great. Seems to work for me!
Thank you very much.

I added your patch to the ticket system.
Maybe someone can investigate and integrate it.


    Reply to author    Forward  
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.
Thomas Wittek  
View profile
 More options Nov 19 2007, 4:36 am
From: Thomas Wittek <streawkc...@googlemail.com>
Date: Mon, 19 Nov 2007 01:36:45 -0800 (PST)
Local: Mon, Nov 19 2007 4:36 am
Subject: Re: Identity bug? Passing non-ASCII characters as kwargs to a handler with @identity.require(identity.not_anonymous ()) gives internal server error
On Nov 18, 10:58 am, Thomas Wittek <streawkc...@googlemail.com> wrote:

> On Nov 16, 10:38 am, Adi <fanet...@gmail.com> wrote:

> > Here's where I have put the 2 extra lines: at the end of the method:

> Oh, great. Seems to work for me!
> Thank you very much.

> I added your patch to the ticket system.
> Maybe someone can investigate and integrate it.

Doesn't work with nested request params (i.e. foo.bar.baz) as they get
converted into nested dicts, so the value `v` may be a `dict` that
doesn't have a method named `encode`: AttributeError: 'dict' object
has no attribute 'encode'.

To fix your fix, you have to do do a recursive conversion:

        def encode_utf8(params):
            for k, v in params.items():
                if type(v) is dict:
                    encode_utf8(v)
                else:
                    params[k] = v.encode('utf-8')

        encode_utf8(cherrypy.request.params)

Funnily, you'll then get an error from CP:

  File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 50, in decode
    decodedParams[key] = value.decode(enc)
AttributeError: 'dict' object has no attribute 'decode'

But I've got a feeling that the real problems are located in another
place, deeper in the system. But unfortunately I don't know much about
TG's/CP's internals.
Maybe this is ultimately a bug in CP. But I really don't know.


    Reply to author    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google