diff --git a/python/fotolia_api/__init__.py b/python/fotolia_api/__init__.py index f76d813..2b7bcbb 100644 --- a/python/fotolia_api/__init__.py +++ b/python/fotolia_api/__init__.py @@ -26,6 +26,13 @@ THUMB_SIZE_MEDIUM = 160 THUMB_SIZE_LARGE = 400 +import os, sys, inspect +# realpath() will make your script run, even if you symlink it :) +cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0])) +if cmd_folder not in sys.path: + sys.path.insert(0, cmd_folder) + + import rest as _rest import error as _error diff --git a/python/fotolia_api/rest.py b/python/fotolia_api/rest.py index 818a54d..6e380c0 100644 --- a/python/fotolia_api/rest.py +++ b/python/fotolia_api/rest.py @@ -1,10 +1,11 @@ import pycurl import json -import StringIO import urllib import time import os +from io import BytesIO + import fotolia_api class Rest: @@ -605,13 +606,12 @@ def _api(self, method, args = {}, auto_refresh_token = True): uri = self._get_full_uri(method, query) curl = self._get_curl(uri, post_data, auto_refresh_token) - buf = StringIO.StringIO() + buf = BytesIO() curl.setopt(pycurl.WRITEFUNCTION, buf.write) - curl.perform() http_code = curl.getinfo(pycurl.HTTP_CODE) - res = json.loads(buf.getvalue()) + res = json.loads(buf.getvalue().decode('utf-8')) if 'error' in res or http_code != 200: error_code = 0 @@ -786,7 +786,7 @@ def recursion(d, base=None): else: new_pair = None if base: - new_pair = "%s%%5B%s%%5D=%s" % (base, urllib.quote(str(key)), urllib.quote(str(value))) + new_pair = "%s%%5B%s%%5D=%s" % (base, urllib.parse.quote(str(key)), urllib.parse.quote(str(value))) pairs.append(new_pair) else: if type(value).__name__ == 'list':