diff --git a/README.mkd b/README.mkd index dd6e932..eab7ea7 100644 --- a/README.mkd +++ b/README.mkd @@ -26,3 +26,11 @@ The following example shows you how to import an image from somewhere on the int result = client.request(**params) print result + + +## Installing on Python 2.6 or older +The package depends on the ``json`` module added in Python 2.7, but we fall +back to importing ``simplejson`` if ``json`` is not available. To make +``python-transloadit`` to work in Python 2.6 or older, install ``simplejson``: + + $ pip install simplejson diff --git a/setup.py b/setup.py index 8dd4c6c..4808db4 100644 --- a/setup.py +++ b/setup.py @@ -3,14 +3,13 @@ from setuptools import setup, find_packages setup(name="transloadit", - version="0.0.1", + version="0.0.5", description="Library for interfacing with Transloadit's API", author="Joe Stump", author_email="joe@joestump.net", url="http://github.com/joestump/python-transloadit", packages = find_packages(), license = "MIT License", - install_requires=['simplejson>=2.1.6'], keywords="transloadit", zip_safe = True, tests_require=['nose', 'coverage']) diff --git a/transloadit/client.py b/transloadit/client.py index 970a7cc..acda21b 100644 --- a/transloadit/client.py +++ b/transloadit/client.py @@ -12,9 +12,12 @@ try: - from django.utils import simplejson as json -except ImportError: + # Should be (manually) installed if using Python 2.6 or older, + # or if you want the speedup for raw bytestrings provided by + # simplejson. import simplejson as json +except ImportError: + import json # Works with python 2.7+ BASE_API = 'http://api2.transloadit.com/assemblies' @@ -45,7 +48,15 @@ def _send_request(self, files, **fields): req.endheaders() req.send(body) errcode, errmsg, headers = req.getreply() - return json.loads(req.file.read()) + output = req.file.read() + try: + return json.loads(output) + except json.JSONDecodeError: + # Workaround for https://github.com/joestump/python-transloadit/issues/5 + output = '{' + output.split('{', 1)[-1] + output = output.rsplit('}', 1)[0] + '}' + return json.loads(output) + def _encode_request(self, fields, files): body = StringIO()