Skip to content

Commit caef8d3

Browse files
committed
Make urllib2 import Python 2/3 compatible
1 parent 71b1bb4 commit caef8d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Adyen/httpclient.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
except ImportError:
1313
pycurl = None
1414

15-
import urllib2
16-
1715
try:
1816
# Python 3
1917
from urllib.parse import urlencode
18+
from urllib.request import Request
19+
from urllib.error import HTTPError
2020
except ImportError:
2121
# Python 2
2222
from urllib import urlencode
23+
from urllib2 import Request, urlopen, HTTPError
2324

2425
from StringIO import StringIO
2526
import json as json_lib
@@ -229,7 +230,7 @@ def _urllib_post(self, url,
229230
raw_store = json
230231

231232
raw_request = json_lib.dumps(json) if json else urlencode(data)
232-
url_request = urllib2.Request(url,data=raw_request)
233+
url_request = Request(url,data=raw_request)
233234
if json:
234235
url_request.add_header('Content-Type','application/json')
235236
elif not data:
@@ -254,8 +255,8 @@ def _urllib_post(self, url,
254255

255256
#URLlib raises all non 200 responses as en error.
256257
try:
257-
response = urllib2.urlopen(url_request, timeout=timeout)
258-
except urllib2.HTTPError as e:
258+
response = urlopen(url_request, timeout=timeout)
259+
except HTTPError as e:
259260
raw_response = e.read()
260261

261262
return raw_response, raw_request, e.getcode(), e.headers

0 commit comments

Comments
 (0)