I can't retrieve simple stock data using quandl in Python
09:06 12 Dec 2024

In Jupyter Notebook I have run a simple Python script which installs quandl, imports quandl, and retrieves my API key (which is definitely correct). However, when I try to access stock data for Apple I keep getting an error message. Here is the code:

pip install quandl
import quandl
quandl.ApiConfig.api_key = 'LWz7bMLgzxrbFJ8n66-T'
aapl = quandl.get('WIKI/AAPL', start_date='2014-01-01', end_date='2016-01-01')

Error message:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\requests\models.py:974, in Response.json(self, **kwargs)
    973 try:
--> 974     return complexjson.loads(self.text, **kwargs)
    975 except JSONDecodeError as e:
    976     # Catch JSON-related errors and raise as requests.JSONDecodeError
    977     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~\anaconda3\Lib\json\__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File ~\anaconda3\Lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File ~\anaconda3\Lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

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

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\quandl\connection.py:84, in Connection.parse(cls, response)
     83 try:
---> 84     return response.json()
     85 except ValueError:

File ~\anaconda3\Lib\site-packages\requests\models.py:978, in Response.json(self, **kwargs)
    975 except JSONDecodeError as e:
    976     # Catch JSON-related errors and raise as requests.JSONDecodeError
    977     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 978     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

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

During handling of the above exception, another exception occurred:

QuandlError                               Traceback (most recent call last)
Cell In[8], line 1
----> 1 aapl = quandl.get('WIKI/AAPL', start_date='2014-01-01', end_date='2016-01-01')

File ~\anaconda3\Lib\site-packages\quandl\get.py:48, in get(dataset, **kwargs)
     46     if dataset_args['column_index'] is not None:
     47         kwargs.update({'column_index': dataset_args['column_index']})
---> 48     data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
     49 # Array
     50 elif isinstance(dataset, list):

File ~\anaconda3\Lib\site-packages\quandl\model\dataset.py:47, in Dataset.data(self, **options)
     45 updated_options = Util.merge_options('params', params, **options)
     46 try:
---> 47     return Data.all(**updated_options)
     48 except NotFoundError:
     49     if handle_not_found_error:

File ~\anaconda3\Lib\site-packages\quandl\operations\list.py:15, in ListOperation.all(cls, **options)
     13     options['params'] = {}
     14 path = Util.constructed_path(cls.list_path(), options['params'])
---> 15 r = Connection.request('get', path, **options)
     16 response_data = r.json()
     17 Util.convert_to_dates(response_data)

File ~\anaconda3\Lib\site-packages\quandl\connection.py:38, in Connection.request(cls, http_verb, url, **options)
     34 options['headers'] = headers
     36 abs_url = '%s/%s' % (ApiConfig.api_base, url)
---> 38 return cls.execute_request(http_verb, abs_url, **options)

File ~\anaconda3\Lib\site-packages\quandl\connection.py:50, in Connection.execute_request(cls, http_verb, url, **options)
     45 response = session.request(method=http_verb,
     46                            url=url,
     47                            verify=ApiConfig.verify_ssl,
     48                            **options)
     49 if response.status_code < 200 or response.status_code >= 300:
---> 50     cls.handle_api_error(response)
     51 else:
     52     return response

File ~\anaconda3\Lib\site-packages\quandl\connection.py:90, in Connection.handle_api_error(cls, resp)
     88 @classmethod
     89 def handle_api_error(cls, resp):
---> 90     error_body = cls.parse(resp)
     92     # if our app does not form a proper quandl_error response
     93     # throw generic error
     94     if 'quandl_error' not in error_body:

File ~\anaconda3\Lib\site-packages\quandl\connection.py:86, in Connection.parse(cls, response)
     84     return response.json()
     85 except ValueError:
---> 86     raise QuandlError(http_status=response.status_code, http_body=response.text)

QuandlError: (Status 403) Something went wrong. Please try again. If you continue to have problems, please contact us at connect@quandl.com.

I have troubleshooted this many times. I have double checked that the API key is correct, I have tried a different dataset to retrieve Apple from and I have tried reformatting the code or using different packages to retrieve the data. I was expecting the command to be successful and a simple "print(aapl.head())" command should return the first 5 rows of data but obviously I have not gotten this far.

python jupyter-notebook stock quandl