Python: Getting INVALID response from PayPal's Sandbox IPN, slowly going insane...
- by thepeanut
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