I get the JSON response by requests.get
req = requests.get(SAMPLE_SCHEDULE_API)
and convert it into dictionary
data = json.loads(req.text)["data"]
When I tried to convert the string into Python dict,
I got ValueError: malformed node or string:
ast.literal_eval(data)
I have no idea how to do this task.
code snippets
def schedules(cls, start_date=None, end_date=None):
import ast
req = requests.get(SAMPLE_SCHEDULE_API)
data = json.loads(req.text)["data"]
ast.literal_eval(data)
return pd.DataFrame(json.loads(req.text)["data"])
JSON response
{
status: "ok",
version: "v1",
data: "[
{"_id":"2015-01-28","end_date":"2015-01-28","estimated_release":1422453600000,"is_projection":false,"is_statement":true,"material_link":null,"start_date":"2015-01-27"},
{"_id":"2015-03-18","end_date":"2015-03-18","estimated_release":1426687200000,"is_projection":false,"is_statement":false,"material_link":null,"start_date":"2015-03-17"},
{"_id":"2015-04-29","end_date":"2015-04-29","estimated_release":1430316000000,"is_projection":false,"is_statement":false,"material_link":null,"start_date":"2015-04-28"},
{"_id":"2015-06-17","end_date":"2015-06-17","estimated_release":1434549600000,"is_projection":false,"is_statement":false,"material_link":null,"start_date":"2015-06-16"},
{"_id":"2015-07-29","end_date":"2015-07-29","estimated_release":1438178400000,"is_projection":false,"is_statement":false,"material_link":null,"start_date":"2015-07-28"}]"
}
Detail error message
Traceback (most recent call last):
File "fomc.py", line 25, in <module>
schedules = FOMC.schedules()
File "fomc.py", line 21, in schedules
ast.literal_eval(data)
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/ast.py", line 86, in literal_eval
return _convert(node_or_string)
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/ast.py", line 58, in _convert
return list(map(_convert, node.elts))
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/ast.py", line 63, in _convert
in zip(node.keys, node.values))
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/ast.py", line 62, in <genexpr>
return dict((_convert(k), _convert(v)) for k, v
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/ast.py", line 85, in _convert
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.Name object at 0x10a19c990>