diff options
author | Magnus Hagander | 2019-01-04 12:48:17 +0000 |
---|---|---|
committer | Magnus Hagander | 2019-01-04 12:48:17 +0000 |
commit | bd4b72ca949c2d08c5abe4b66a6aa252b48d1cb4 (patch) | |
tree | 20ebce3c061ed89030e04259850450e3a8370825 /postgresqleu/paypal/util.py | |
parent | 8dd9c29af824db23db5ea5541083b9fa170a6734 (diff) |
Switch to using requests for http requests
It's a lot cleaner API than urllib2, and will be easier once we port
version.
Hopefully this doesn't break something. Probably it does break encoding
somewhere, because py2.
Diffstat (limited to 'postgresqleu/paypal/util.py')
-rw-r--r-- | postgresqleu/paypal/util.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/postgresqleu/paypal/util.py b/postgresqleu/paypal/util.py index 7c7b42bb..66ebb0fe 100644 --- a/postgresqleu/paypal/util.py +++ b/postgresqleu/paypal/util.py @@ -1,7 +1,6 @@ from django.conf import settings -import urllib2 -from urllib import urlencode +import requests from urlparse import parse_qs from decimal import Decimal import itertools @@ -23,8 +22,12 @@ class PaypalAPI(object): def _api_call(self, command, params): params.update(self.accessparam) params['METHOD'] = command - resp = urllib2.urlopen(self.API_ENDPOINT, urlencode(params)).read() - q = parse_qs(resp) + + resp = requests.post(self.API_ENDPOINT, data=params) + if resp.status_code != 200: + raise Exception("API error from paypal, status {0}".format(resp.status_code)) + + q = parse_qs(resp.text) if q['ACK'][0] != 'Success': raise Exception("API error from paypal: {0}/{1}".format(q['L_SHORTMESSAGE0'][0], q['L_LONGMESSAGE0'][0])) return q |