I am doing a payment with PayPal. Here is how it works properly with requests
:
res = requests.post(get_payment_info_url, headers=headers, data=params)
res_data = res.json()
But then when I try and do the same request with the urlfetch
, it gives me an error (a 200 response from PayPal, but the payment Fails):
res = urlfetch.fetch(url=make_payment_url, payload=params, method=urlfetch.POST, headers=headers)
res_data = json.loads(res)
{u'responseEnvelope': {u'timestamp': u'2015-02-15T23:21:52.729-08:00', u'ack': u'Failure', u'build': u'15089777', u'correlationId': u'e202988541fde'},
u'error': [{u'domain': u'PLATFORM', u'message': u'Invalid request: {0}', u'severity': u'Error', u'subdomain':
u'Application', u'category': u'Application', u'errorId': u'580001'}]}
It seems that maybe Google is stripping headers or something? How would I then make this request if Google is doing that?
Finally, is there any reason to use urlfetch
over requests
(which I've imported locally into my GAE project? Requests seems so much easier and 'friendly' to use.
Take a look at the https://github.com/paypal/PayPal-Python-SDK I managed to patch this lib easily to work with GAE as described here: https://github.com/paypal/PayPal-Python-SDK/issues/66
Requests works on GAE, but only version 2.3.0(!)
On Google Appengine (version 1.9.17) requests version 2.3.0 (only!) works IN PRODUCTION (but not on SDK) if you have billing enabled, which enables sockets support.
requests on the Appengine SDK fails with all https:// requests:
requests version 2.4.1 fails with:
requests version 2.5.1 fails with:
Info on sockets support: https://cloud.google.com/appengine/docs/python/sockets/
For this, the payload needs to be urlencoded. Here is what worked: