Home > Software design >  JSONDecodeError Extra data: line 1 column 9 - line 1 column 36 (char 8 - 35), How to make a batch re
JSONDecodeError Extra data: line 1 column 9 - line 1 column 36 (char 8 - 35), How to make a batch re

Time:09-21

I am trying to make a batch request on iexapicloud. Here is the documentation I am using.
https://iexcloud.io/docs/api/#batch-requests

To test out batch requests I used a sandbox api and a few random stock tickers and I keep getting a json error:

import numpy as np
import pandas as pd   
import requests
import json
  

sandbox_api = 'Tpk_002d9beb3a9c489d98368b78bd1ecf00'

url = f'https://sandbox.iexapis.com/stable/stock/market/batch?symbols=AAPL,FB,TSLA&types=quote?token={sandbox_api}'

data = requests.get(url).json()

 

JSONDecodeError: Extra data: line 1 column 9 - line 1 column 36 (char 8 - 35)

CodePudding user response:

Replace the last ? to & in URL:

import requests


sandbox_api = "Tpk_002d9beb3a9c489d98368b78bd1ecf00"
url = f"https://sandbox.iexapis.com/stable/stock/market/batch?symbols=AAPL,FB,TSLA&types=quote&token={sandbox_api}"

data = requests.get(url).json()
print(data)

Prints:

{
    "AAPL": {
        "quote": {
            "avgTotalVolume": 81528699,
            "calculationPrice": "tops",
            "change": -3.35,
            "changePercent": -0.02349,
            "close": 0,
            "closeSource": "fcfioali",
            "closeTime": None,
            "companyName": "Apple Inc",
            "currency": "USD",
            "delayedPrice": None,
            "delayedPriceTime": None,
            "extendedChange": None,

...
  • Related