From 480166016d63638fe7c4e12738b9129866c8f506 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Fri, 14 Mar 2014 22:27:08 +0100 Subject: [PATCH 1/8] Use the json module as fallback for simplejson, and remove the hard dependency on simplejson. The motivation for this is that simplejson is not required, and it causes problems with Django 1.5 (see https://github.com/simplejson/simplejson/issues/37). For most cases, the speedup of simplejson is not required, and if the system does not have a C compiler, simplejson is actually slower than the json module (see https://code.djangoproject.com/ticket/18023). --- README.mkd | 8 ++++++++ setup.py | 1 - transloadit/client.py | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) 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..fe73cf6 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,6 @@ 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..923a70f 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' From 1103970e40625c6a20dd91602036f998e2290ad0 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 14:51:22 +0200 Subject: [PATCH 2/8] Print the output causing json decode error. --- transloadit/client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/transloadit/client.py b/transloadit/client.py index 923a70f..f28fcda 100644 --- a/transloadit/client.py +++ b/transloadit/client.py @@ -48,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() + print + print '*' * 70 + print + print 'Transloadit output:', output + print + print '*' * 70 + print + return json.loads(output) def _encode_request(self, fields, files): body = StringIO() From 6c836da34abe7a9056e32cc57664b345aff05a2c Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 14:58:25 +0200 Subject: [PATCH 3/8] Set version to 0.0.2. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fe73cf6..fc760ca 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name="transloadit", - version="0.0.1", + version="0.0.2", description="Library for interfacing with Transloadit's API", author="Joe Stump", author_email="joe@joestump.net", From 5790995437f7d71452fbb2b645351c2ceaf4b813 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 15:10:51 +0200 Subject: [PATCH 4/8] Workaround for https://github.com/joestump/python-transloadit/issues/5. --- transloadit/client.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/transloadit/client.py b/transloadit/client.py index f28fcda..e8eeb38 100644 --- a/transloadit/client.py +++ b/transloadit/client.py @@ -49,14 +49,13 @@ def _send_request(self, files, **fields): req.send(body) errcode, errmsg, headers = req.getreply() output = req.file.read() - print - print '*' * 70 - print - print 'Transloadit output:', output - print - print '*' * 70 - print - return json.loads(output) + try: + return json.loads(output) + except json.JSONDecodeError: + # Workaround for https://github.com/joestump/python-transloadit/issues/5 + output = '{' + output.split('{', 1)[-1] + return json.loads(output) + def _encode_request(self, fields, files): body = StringIO() From 9fb08ae5eae8ad936ce010936e4c888d05fd3f90 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 15:11:24 +0200 Subject: [PATCH 5/8] Released 0.0.3. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fc760ca..c004a52 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name="transloadit", - version="0.0.2", + version="0.0.3", description="Library for interfacing with Transloadit's API", author="Joe Stump", author_email="joe@joestump.net", From 111a3d36960bf70a008780f652c6a04f9c674d14 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 15:24:46 +0200 Subject: [PATCH 6/8] Debugging JSONDecodeError. --- setup.py | 2 +- transloadit/client.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c004a52..6850749 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name="transloadit", - version="0.0.3", + version="0.0.4", description="Library for interfacing with Transloadit's API", author="Joe Stump", author_email="joe@joestump.net", diff --git a/transloadit/client.py b/transloadit/client.py index e8eeb38..b418aef 100644 --- a/transloadit/client.py +++ b/transloadit/client.py @@ -54,6 +54,13 @@ def _send_request(self, files, **fields): except json.JSONDecodeError: # Workaround for https://github.com/joestump/python-transloadit/issues/5 output = '{' + output.split('{', 1)[-1] + print + print '*' * 70 + print + print 'Transloadit output:', output + print + print '*' * 70 + print return json.loads(output) From 3c2450add5f629fea9d7f85ac05f3ba10b7cc417 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 15:31:52 +0200 Subject: [PATCH 7/8] Workaround for trailing chars in transloadit output. --- transloadit/client.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/transloadit/client.py b/transloadit/client.py index b418aef..acda21b 100644 --- a/transloadit/client.py +++ b/transloadit/client.py @@ -54,13 +54,7 @@ def _send_request(self, files, **fields): except json.JSONDecodeError: # Workaround for https://github.com/joestump/python-transloadit/issues/5 output = '{' + output.split('{', 1)[-1] - print - print '*' * 70 - print - print 'Transloadit output:', output - print - print '*' * 70 - print + output = output.rsplit('}', 1)[0] + '}' return json.loads(output) From 7034b9132409869c512291ac6a9ddf8078b29246 Mon Sep 17 00:00:00 2001 From: "Espen A. Kristiansen" Date: Wed, 21 Oct 2015 15:32:24 +0200 Subject: [PATCH 8/8] Released 0.0.5. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6850749..4808db4 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name="transloadit", - version="0.0.4", + version="0.0.5", description="Library for interfacing with Transloadit's API", author="Joe Stump", author_email="joe@joestump.net",