Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Adyen/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@
except ImportError:
pycurl = None

import urllib2
try:
# Python 3
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from urllib.error import HTTPError
except ImportError:
# Python 2
from urllib import urlencode
from urllib2 import Request, urlopen, HTTPError

try:
# Python 3
from io import StringIO
except ImportError:
# Python 2
from StringIO import StringIO

from urllib import urlencode
from StringIO import StringIO
import json as json_lib
import re
import base64
Expand Down Expand Up @@ -223,7 +236,7 @@ def _urllib_post(self, url,
raw_store = json

raw_request = json_lib.dumps(json) if json else urlencode(data)
url_request = urllib2.Request(url,data=raw_request)
url_request = Request(url,data=raw_request)
if json:
url_request.add_header('Content-Type','application/json')
elif not data:
Expand All @@ -248,8 +261,8 @@ def _urllib_post(self, url,

#URLlib raises all non 200 responses as en error.
try:
response = urllib2.urlopen(url_request, timeout=timeout)
except urllib2.HTTPError as e:
response = urlopen(url_request, timeout=timeout)
except HTTPError as e:
raw_response = e.read()

return raw_response, raw_request, e.getcode(), e.headers
Expand Down