Skip to content

JSON decode Error in get_sidra_table function #178

@fccoelho

Description

@fccoelho
from pysus.online_data import IBGE
IBGE.get_sidra_table(200,territorial_level=6,classification=2, categories='all')

generates the following exception:

JSONDecodeError                           Traceback (most recent call last)
Cell In[73], line 1
----> 1 rio = IBGE.get_sidra_table(200,territorial_level=6, geocode=3334557,period='last',classification=2, categories='all')
      2 rio

File ~/MEGAsync/Cursos/curso-pysus/.venv/lib/python3.11/site-packages/pysus/online_data/IBGE.py:103, in get_sidra_table(table_id, territorial_level, geocode, period, variables, classification, categories, format, decimals, headers)
    101 try:
    102     with (get_legacy_session() as s, s.get(url) as response):
--> 103         df = pd.DataFrame(response.json())
    104 except HTTPError as exc:
    105     response = requests.get(url)

File ~/MEGAsync/Cursos/curso-pysus/.venv/lib/python3.11/site-packages/requests/models.py:975, in Response.json(self, **kwargs)
    971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

we probably need to use pd.read_json here instead of passing the JSON directly to the DataFrame constructor.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions