Skip to content

Instantly share code, notes, and snippets.

@jennyd
Last active August 29, 2015 14:19
Show Gist options
  • Save jennyd/2edf78206634d18a4a6a to your computer and use it in GitHub Desktop.
Save jennyd/2edf78206634d18a4a6a to your computer and use it in GitHub Desktop.
requests 2.6.1 errors on decoding JSON in PP response
# with performanceplatform-client==0.8.2
from performanceplatform.client import DataSet
dataset = DataSet.from_group_and_type('https://www.performance.service.gov.uk/data',
'govuk-info',
'page-contacts')
query_parameters = {
'start_at': '2015-03-12T00:00:00Z',
'period': 'day',
'end_at': '2015-04-23T00:00:00Z',
'collect': 'total:sum',
'group_by': 'pagePath',
'filter_by_prefix': 'pagePath:/a'
}
json_data = dataset.get(query_parameters)
print json_data
# with requests 2.6.0:
$ python example.py
{u'warning': u'Warning: This data-set is unpublished. Data may be subject to change or be inaccurate.', u'data': [{u'total:sum': 1.0, u'pagePath': u'/aaib-reports', u'_count': 1.0, u'_group_count': 1, u'values': [{u'total:sum': None, u'_end_at': u'2015-03-13T00:00:00+00:00', u'_count': 0, u'_start_at': u'2015-03-12T00:00:00+00:00'}, ...
# with requests 2.6.1:
$ python example.py
Traceback (most recent call last):
File "example.py", line 17, in <module>
json_data = dataset.get(query_parameters)
File "/Users/jennyduckett/virtualenvs/performanceplatform-govuk-stats/lib/python2.7/site-packages/performanceplatform/client/data_set.py", line 51, in get
return self._get(self._to_query_string(query_parameters))
File "/Users/jennyduckett/virtualenvs/performanceplatform-govuk-stats/lib/python2.7/site-packages/performanceplatform/client/base.py", line 53, in _get
return self._request('GET', path)
File "/Users/jennyduckett/virtualenvs/performanceplatform-govuk-stats/lib/python2.7/site-packages/performanceplatform/client/base.py", line 120, in _request
json = response.json()
File "/Users/jennyduckett/virtualenvs/performanceplatform-govuk-stats/lib/python2.7/site-packages/requests/models.py", line 819, in json
return json.loads(self.text, **kwargs)
File "/opt/boxen/homebrew/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/opt/boxen/homebrew/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/boxen/homebrew/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
@jennyd
Copy link
Author

jennyd commented Apr 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment