Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal IPN POST request encoding

When trying to work with PayPal IPN POST payload in Pyramid (and, probably, others) I get decoding errors:

[...]
 File "./project/views.py", line 716, in paypal_ipn
    message = request.POST
  File "build/bdist.linux-x86_64/egg/webob/request.py", line 745, in POST
  File "build/bdist.linux-x86_64/egg/webob/multidict.py", line 74, in from_fieldstorage
  File "build/bdist.linux-x86_64/egg/webob/multidict.py", line 67, in <lambda>
  File "/sites/ts/lib64/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf3 in position 5: invalid continuation byte

How to fix that?

like image 493
dsx Avatar asked May 31 '12 15:05

dsx


2 Answers

Edit your "question" to be a real question and we'll be good to go!


For some ungodly reason PayPal still isn't in 21st century and still uses Windows-1252 encoding by default. That might create some problems as it is quite reasonable to expect unicode to be an encoding of choice nowadays.

That might result in something like following traceback when using Pyramid:

[...]
 File "./project/views.py", line 716, in paypal_ipn
    message = request.POST
  File "build/bdist.linux-x86_64/egg/webob/request.py", line 745, in POST
  File "build/bdist.linux-x86_64/egg/webob/multidict.py", line 74, in from_fieldstorage
  File "build/bdist.linux-x86_64/egg/webob/multidict.py", line 67, in <lambda>
  File "/sites/ts/lib64/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf3 in position 5: invalid continuation byte

To fix that you have to either:

  1. Click on «Profile» link under «My Account»
  2. In «Selling Preferences» column find «Language Encoding»
  3. Click on «More options»
  4. Select «UTF-8» and save

Or

  1. Click on «Profile» link under «My Account»
  2. Click on «My selling tools» on the right
  3. Find «PayPal button language encoding» link (should be at the bottom)
  4. Click on «More options»
  5. Select «UTF-8» and save

Depending on type of your PayPal account. Hope that would save someone and hour of life.

like image 160
Sterling Bourne Avatar answered Oct 29 '22 02:10

Sterling Bourne


For some ungodly reason PayPal still isn't in 21st century and still uses Windows-1252 encoding by default. That might create some problems as it is quite reasonable to expect unicode to be an encoding of choice nowadays.

To fix that you have to either:

  1. Click on «Profile» link under «My Account»
  2. In «Selling Preferences» column find «Language Encoding»
  3. Click on «More options»
  4. Select «UTF-8» and save

Or

  1. Click on «Profile» link under «My Account»
  2. Click on «My selling tools» on the right
  3. Find «PayPal button language encoding» link (should be at the bottom)
  4. Click on «More options»
  5. Select «UTF-8» and save

Depending on type of your PayPal account. Hope that would save someone an hour of life.

like image 37
dsx Avatar answered Oct 29 '22 01:10

dsx