Python Forum
JSON Decode error when using API to create dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSON Decode error when using API to create dataframe
#1
Hi there. I am new to python and I'm attempting to use the capiq-python api to create a dataframe. I'm hoping that someone with a Capital IQ account would be able to debug the issue below. (Note that USERNAME and PASSWORD in the code below is in place of my actual username and password

When I run this code script (I've run it in R using the Reticulate package)

from capiq.capiq_client import CapIQClient
ciq_client = CapIQClient("USERNAME", "PASSWORD")
data = ciq_client.gdshe(['WMT:', "ibm:"],['IQ_CLOSEPRICE'], ['close_price'], start_date='11/12/2010',end_date='11/18/2010')
data_content = json.loads(data)
I get the following error

Error in py_run_file_impl(file, local, convert) : 
  JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Any ideas on how to debug this? TIA!
Reply
#2
Looking at the source code you don't get JSON string but dict object. i.e. the python wrapper processed the json string that was returned from the request. So don't do json.loads(). Print data and type(data) so that you see what you actually get.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
@buran using print(data) still gives the same error. Could it have something to do with the square brackets I have in my code chunk?"[]"
Reply
#4
can you show the full traceback you get? I think square brackets are not the problem, but not sure about 'WMT:', "ibm:" All that said - I am not familiar with that API or the wrapper and the docs are really scarce.
actually, looking at the tests, it seems ok.
there is exactly the same line. I guess you took it from there.

print(client.gdshe(['WMT:', "ibm:"],['IQ_CLOSEPRICE'], ['close_price'], start_date='11/12/2010',end_date='11/18/2010'))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Please, when you cross-post, let us know
https://stackoverflow.com/questions/6567...-in-python
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  json loads throwing error mpsameer 8 663 Jan-23-2024, 07:04 AM
Last Post: deanhystad
  json decoding error deneme2 10 3,582 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  Create new dataframe from old dataframe arvin 3 956 Jan-31-2023, 01:23 PM
Last Post: jefsummers
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,365 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  Decode string ? JohnnyCoffee 1 811 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  python requests library .JSON() error mHosseinDS86 6 3,383 Dec-19-2022, 08:28 PM
Last Post: deanhystad
  How do you create a scatterplot of dataframe using matplotlib? asdad 2 855 Dec-07-2022, 04:53 PM
Last Post: Larz60+
  Read nested data from JSON - Getting an error marlonbown 5 1,352 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Convert python dataframe to nested json kat417 1 6,308 Mar-18-2022, 09:14 PM
Last Post: kat417
  Cannot convert the series to <class 'int'> when trying to create new dataframe column Mark17 3 8,472 Jan-20-2022, 05:15 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020