From d57fe60fc8ddc991728250b21db4249b2c961b01 Mon Sep 17 00:00:00 2001 From: crice937 Date: Tue, 28 Apr 2015 21:07:46 -0400 Subject: [PATCH 1/3] Invalid Control Character Error Fix Passing the 'strict=False' argument in 'response.json()' prevents the invalid control character error which occurs if there is a control character present in the returned JSON. --- arcgis/arcgis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcgis/arcgis.py b/arcgis/arcgis.py index 905885d..965b8be 100644 --- a/arcgis/arcgis.py +++ b/arcgis/arcgis.py @@ -87,7 +87,7 @@ def get_json(self, layer, where="1 = 1", fields=[], count_only=False, srid='4326 'orderByFields': "OBJECTID", 'returnCountOnly': count_only }) - return response.json() + return response.json(strict=False) def get_descriptor_for_layer(self, layer): """ From b8402a098fde4679d402565fa594965d26d8e886 Mon Sep 17 00:00:00 2001 From: crice937 Date: Wed, 29 Apr 2015 11:15:16 -0400 Subject: [PATCH 2/3] JSON Validator Defines a new class, validate_json. This class takes the resulting JSON from get, validates it, and either prints to a defined file or throws an error message. --- arcgis/arcgis.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arcgis/arcgis.py b/arcgis/arcgis.py index 965b8be..cad41d2 100644 --- a/arcgis/arcgis.py +++ b/arcgis/arcgis.py @@ -175,6 +175,14 @@ def getMultiple(self, layers, where="1 = 1", fields=[], srid='4326', layer_name_ 'features': features } + def validate_json(self, filename, data="json_query"): + good_request = requests.post("http://geojsonlint.com/validate", data).__str__() + if good_request == "": + f = open(filename, "w") + f.write(json_query) + f.close() + else: + print "The GeoJSON gathered from the specified layer is invalid." def urljoin(*args): """ From 32a31e7a094b14cd203c9bd550767259e3958de6 Mon Sep 17 00:00:00 2001 From: crice937 Date: Wed, 29 Apr 2015 11:18:03 -0400 Subject: [PATCH 3/3] Fix JSON references Update references to json to reference geojson --- arcgis/arcgis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcgis/arcgis.py b/arcgis/arcgis.py index cad41d2..25ac133 100644 --- a/arcgis/arcgis.py +++ b/arcgis/arcgis.py @@ -175,11 +175,11 @@ def getMultiple(self, layers, where="1 = 1", fields=[], srid='4326', layer_name_ 'features': features } - def validate_json(self, filename, data="json_query"): + def validate_geojson(self, filename, data="geojson_query"): good_request = requests.post("http://geojsonlint.com/validate", data).__str__() if good_request == "": f = open(filename, "w") - f.write(json_query) + f.write(data) f.close() else: print "The GeoJSON gathered from the specified layer is invalid."