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
Unicode Error accessing request.params
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
  4 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
 
Brian Brinegar  
View profile  
 More options Jun 17 2012, 10:42 pm
From: Brian Brinegar <brian.brine...@gmail.com>
Date: Sun, 17 Jun 2012 22:42:16 -0400
Local: Sun, Jun 17 2012 10:42 pm
Subject: Unicode Error accessing request.params
I have a pyramid 1.2 application which processes donations made via
PayPal using a service called PayPal Instant Payment Notification.
Today, we had a donation from an international user with non-ascii
characters in their last name. PayPal makes a post request to our
server with information about the pyramid view that handles these the
request failed when I tried to access the last name from
request.params.get('last_name')

I believe requests are encoded as windows-1252, not UTF-8, which is
causing this error. Unfortunately, I do not have the option of
changing the encoding method on PayPal's end.

  File "/home/mario/webapps/mario_dyn/mario/mario/views/donate.py",
line 241, in donate_ipn
    value = request.params.get(key)
  File "/home/mario/webapps/mario_dyn/lib/python2.7/UserDict.py", line
168, in get
    return self[key]
  File "/home/mario/webapps/mario_dyn/lib/python2.7/webob/multidict.py",
line 312, in __getitem__
    return self._decode_value(self.multi.__getitem__(self._encode_key(key)))
  File "/home/mario/webapps/mario_dyn/lib/python2.7/webob/multidict.py",
line 301, in _decode_value
    value = value.decode(self.encoding, self.errors)
  File "/home/mario/webapps/mario_dyn/lib/python2.7/encodings/utf_8.py",
line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe5 in position 1:
invalid continuation byte

So, my question is, how do I tell the the request that the request is
encoded windows-1252 not utf-8, or convert it to utf-8 prior to
accessing the params MultiDict.

Thank you,
Brian


 
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.
Blaise Laflamme  
View profile  
 More options Jun 18 2012, 10:09 am
From: Blaise Laflamme <bla...@laflamme.org>
Date: Mon, 18 Jun 2012 07:09:35 -0700 (PDT)
Local: Mon, Jun 18 2012 10:09 am
Subject: Re: Unicode Error accessing request.params

Hi Brian,

yes you can change the encoding on paypal's end. Look here:

Profile > My Selling Tools > Paypal button language encoding > More options

And select utf8 on both popups.


 
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.
Brian Brinegar  
View profile  
 More options Jun 18 2012, 10:15 am
From: Brian Brinegar <brian.brine...@gmail.com>
Date: Mon, 18 Jun 2012 10:15:46 -0400
Local: Mon, Jun 18 2012 10:15 am
Subject: Re: Unicode Error accessing request.params
Blaise,

Unfortunately, I do not have access to the Paypal encoding settings.
I'm tracking donations made to an account I do not own.

So, I need to be able to accept windows-1252 encoding in my pyramid app.

Is there a way I can decode and re-encode the request.body before it's
parsed into the params MultiDict?

Brian


 
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.
Michael Merickel  
View profile  
 More options Jun 18 2012, 3:43 pm
From: Michael Merickel <mmeri...@gmail.com>
Date: Mon, 18 Jun 2012 15:43:19 -0400
Local: Mon, Jun 18 2012 3:43 pm
Subject: Re: Unicode Error accessing request.params
From my unaccepted SO answer.. AFAIK it's correct though.

http://stackoverflow.com/a/11061308/704327

Pyramid supports a request factory. You can use this to decode the request.

def request_factory(environ):
    req = pyramid.request.Request(environ)
    return req.decode(charset='gbk')

config.set_request_factory(request_factory)

This means that the request passed around within pyramid will be using
the gbk charset. Failure to decode the request with this charset will
cause UnicodeDecodeError exceptions so you may want to add extra logic
to your request factory to handle these things.

On Mon, Jun 18, 2012 at 10:15 AM, Brian Brinegar


 
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 »