pombreda / tipfy

Automatically exported from code.google.com/p/tipfy
Other
0 stars 0 forks source link

openid and unicode #72

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. set up a GoogleAccount with foreign charactes in name, for example "Šimon"
2. try to login using openid with this account
3. it will fail see screenshot

It will try to create url with all the parameters urlencoded as parameters but 
it will choke on the non ascii characters. It has to be fixed so that it will 
accept all kind of characters.

This was found in repository version 0.7

possible solution would be:

put/replace at the end of tipfy/auth/openid.py

def make_full_url(base, args):
    if "?" in base:
        delimiter = "&"
    else:
        delimiter = "?"

    import types

    data = dict([(k,v.encode('utf-8') if type(v) is types.UnicodeType else v) for (k,v) in args.items()])
    return base + delimiter + urllib.urlencode(data)

Original issue reported on code.google.com by *...@simonpayne.cz on 15 Jan 2011 at 1:53

Attachments:

GoogleCodeExporter commented 9 years ago
I have the same issue:

Traceback (most recent call last):

  File "/home/carlos/sources/tipfy_project/app/distlib/tipfy/__init__.py", line 442, in wsgi_app
    response = self.handle_exception(request, e)

  File "/home/carlos/sources/tipfy_project/app/distlib/tipfy/__init__.py", line 430, in wsgi_app
    rv = self.dispatch(request)

  File "/home/carlos/sources/tipfy_project/app/distlib/tipfy/__init__.py", line 559, in dispatch
    return handler(self, request)(method, **request.rule_args)

  File "/home/carlos/sources/tipfy_project/app/distlib/tipfy/__init__.py", line 165, in __call__
    response = method(*args, **kwargs)

  File "/home/carlos/sources/tipfy_project/app/lib/users/handlers.py", line 181, in get
    return self.get_authenticated_user(self._on_auth)

  File "/home/carlos/sources/tipfy_project/app/distlib/tipfy/ext/auth/google.py", line 120, in get_authenticated_user
    return OpenIdMixin.get_authenticated_user(self, callback)

  File "/home/carlos/sources/tipfy_project/app/distlib/tipfy/ext/auth/openid.py", line 81, in get_authenticated_user
    url = openid_endpoint + '?' + urllib.urlencode(args)

  File "/usr/local/python2.5/lib/python2.5/urllib.py", line 1250, in urlencode
    v = quote_plus(str(v))

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 2: 
ordinal not in range(128)

I fix it changing:
    args = dict((k, v[-1]) for k, v in self.request.args.lists())
by:
    args = dict((k, v[-1].encode('utf-8')) for k, v in self.request.args.lists())
in tipfy/ext/auth/openid.py (line 79).

Original comment by carlos.e...@gmail.com on 31 Mar 2011 at 10:11