Python interface to PayPal - urllib.urlencode non-ASCII characters failing

前端 未结 3 2180
粉色の甜心
粉色の甜心 2021-01-31 19:10

I am trying to implement PayPal IPN functionality. The basic protocol is as such:

  1. The client is redirected from my site to PayPal\'s site to complete payment. He l
3条回答
  •  无人共我
    2021-01-31 20:02

    Try converting the params dictionary to utf-8 first... urlencode seems to like that better than unicode:

    params = urllib.urlencode(dict([k, v.encode('utf-8')] for k, v in params.items()))
    

    Of course, this assumes your input is unicode. If your input is something other than unicode, you'll want to decode it to unicode first, then encode it:

    params['foo'] = my_raw_input.decode('iso-8859-1')
    params = urllib.urlencode(dict([k, v.encode('utf-8')] for k, v in params.items()))
    

提交回复
热议问题