fix ox.api
This commit is contained in:
parent
83cf8eea53
commit
b70dfecccc
1 changed files with 4 additions and 4 deletions
|
@ -5,7 +5,7 @@ from __future__ import with_statement
|
|||
|
||||
from six.moves import http_cookiejar as cookielib
|
||||
import gzip
|
||||
from six import StringIO
|
||||
from six import BytesIO
|
||||
from six.moves import urllib
|
||||
from types import MethodType
|
||||
|
||||
|
@ -30,7 +30,7 @@ class API(object):
|
|||
else:
|
||||
self._cj = cookielib.CookieJar()
|
||||
self._opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self._cj),
|
||||
urllib.HTTPHandler(debuglevel=self.debuglevel))
|
||||
urllib.request.HTTPHandler(debuglevel=self.debuglevel))
|
||||
self._opener.addheaders = [
|
||||
('User-Agent', '%s/%s' % (self.__name__, self.__version__))
|
||||
]
|
||||
|
@ -64,7 +64,7 @@ class API(object):
|
|||
result = {}
|
||||
try:
|
||||
body = str(form)
|
||||
request = urllib.reuqest.Request(str(url))
|
||||
request = urllib.request.Request(str(url))
|
||||
request.add_header('Content-type', form.get_content_type())
|
||||
request.add_header('Content-Length', str(len(body)))
|
||||
request.add_header('Accept-Encoding', 'gzip, deflate')
|
||||
|
@ -72,7 +72,7 @@ class API(object):
|
|||
f = self._opener.open(request)
|
||||
result = f.read()
|
||||
if f.headers.get('content-encoding', None) == 'gzip':
|
||||
result = gzip.GzipFile(fileobj=StringIO.StringIO(result)).read()
|
||||
result = gzip.GzipFile(fileobj=BytesIO(result)).read()
|
||||
result = result.decode('utf-8')
|
||||
return json.loads(result)
|
||||
except urllib.error.HTTPError as e:
|
||||
|
|
Loading…
Reference in a new issue