Python: Getting INVALID response from PayPal's Sandbox IPN, slowly going insane...

Posted by thepeanut on Stack Overflow See other posts from Stack Overflow or by thepeanut
Published on 2010-02-22T20:32:07Z Indexed on 2010/04/05 2:43 UTC
Read the original article Hit count: 475

Filed under:
|
|
|
|

Hi All

I am trying to implement a simple online payment system using PayPal, however I have tried everything I know and am still getting an INVALID response.

I know it's nothing too simple, because I get a VERIFIED response when using the IPN simulator. I have tried putting the items into a dict first, I have tried fixing the encoding, and still nothing. PayPal says the reasons for an INVALID response could be:

  • Sending wrong items or in wrong order (pretty sure it's not this)
  • Sending to the wrong address (definitely not this)
  • Encoding items incorrectly (I dont think it's this, set encoding to UTF-8 on both paypal and my script)

The following is the snippet concerned:


f = cgi.FieldStorage()
newparams = 'cmd=_notify-validate'
for key in f.keys():
    val = f[key].value
    newparams += '&' + urlencode({key: val.encode('utf-8')})

req = urllib2.Request(PP_URL, newparams)
req.add_header("Content-type", "application/x-www-form-urlencoded")
http = urllib2.urlopen(req)
ret = http.read()
fi.write(ret + '\n')
if ret == 'VERIFIED':
    #*do stuff*

Can anyone suggest anything I can do to fix this?!

Cheers

Sam

© Stack Overflow or respective owner

Related posts about python

Related posts about paypal