Better error messages
J535D165 opened this issue · 0 comments
J535D165 commented
404 results in a error like this:
In [1]: import cbsodata
...: import pandas as pd
...: data = pd.DataFrame(cbsodata.get_data('47015NED'))
...: print(data.head())
...:
/Users/jonathandebruin/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-1-7c8e94229f87> in <module>()
1 import cbsodata
2 import pandas as pd
----> 3 data = pd.DataFrame(cbsodata.get_data('47015NED'))
4 print(data.head())
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/cbsodata.py in get_data(table_id, dir, typed, select, filters)
277
278 metadata = download_data(table_id, dir=dir, typed=typed,
--> 279 select=select, filters=filters)
280
281 if "TypedDataSet" in metadata.keys():
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/cbsodata.py in download_data(table_id, dir, typed, select, filters)
155
156 # http://opendata.cbs.nl/ODataApi/OData/37506wwm?$format=json
--> 157 metadata_tables = _download_metadata(table_id, "")
158
159 # The names of the tables with metadata
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/cbsodata.py in _download_metadata(table_id, metadata_name, select, filters)
80 r = requests.get(url, params=params)
81
---> 82 res = r.json(encoding='utf-8')
83 res_value = res['value']
84
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/requests/models.py in json(self, **kwargs)
894 # used.
895 pass
--> 896 return complexjson.loads(self.text, **kwargs)
897
898 @property
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/simplejson/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw)
533 raise TypeError("use_decimal=True implies parse_float=Decimal")
534 kw['parse_float'] = Decimal
--> 535 return cls(encoding=encoding, **kw).decode(s)
536
537
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/simplejson/decoder.py in decode(self, s, _w, _PY3)
368 if _PY3 and isinstance(s, bytes):
369 s = str(s, self.encoding)
--> 370 obj, end = self.raw_decode(s)
371 end = _w(s, end).end()
372 if end != len(s):
~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/simplejson/decoder.py in raw_decode(self, s, idx, _w, _PY3)
398 elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':
399 idx += 3
--> 400 return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)