For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
3 0 0 0

JSONDecodeError in Python API

When I try to retrieve data using the Pyhon API, I get a JSONDecodeError. I am using Python 3.8.5 (64-bit) on Windows 10 and version 1.1.6.post3 of the eikon package. The same code worked fine, i.e. produced the expected results, a couple of months ago. I updated the eikon package after I got the error message. But this did not resolve the problem.

The following request

ek.get_timeseries('.STOXX50E', start_date='2018-10-01', end_date='2020-09-30')

now produces this error message:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-9-99d1fe36af3b> in <module>
----> 1 df_eurostoxx = ek.get_timeseries('.STOXX50E', start_date='2018-10-01', end_date='2020-09-30')

c:\users\dietmar\venv\python38_finance\lib\site-packages\eikon\time_series.py in get_timeseries(rics, fields, start_date, end_date, interval, count, calendar, corax, normalize, raw_output, debug)
    180                 raise ValueError(error_msg)
    181 --> 182     ts_result = eikon.json_requests.send_json_request(TimeSeries_UDF_endpoint, payload, debug=debug)
    183     184     # Catch all errors to raise a warning

c:\users\dietmar\venv\python38_finance\lib\site-packages\eikon\json_requests.py in send_json_request(entity, payload, debug)
     99     100             if response.status_code == 200:
--> 101                 result = response.json()
    102                 logger.trace('Response size: {}'.format(sys.getsizeof(json.dumps(result))))
    103 
c:\users\dietmar\venv\python38_finance\lib\site-packages\httpx\_models.py in json(self, **kwargs)
   1081                 except UnicodeDecodeError:
   1082                     pass
-> 1083         return jsonlib.loads(self.text, **kwargs)
   1084    1085     @property 
C:\Program Files\Python38\lib\json\__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    355             parse_int is None and parse_float is None and
    356             parse_constant is None and object_pairs_hook is None and not kw):
--> 357         return _default_decoder.decode(s)
    358     if cls is None:
    359         cls = JSONDecoder 
C:\Program Files\Python38\lib\json\decoder.py in decode(self, s, _w)
    335     336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

C:\Program Files\Python38\lib\json\decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(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 3 column 1 (char 4)
eikoneikon-data-apipythonworkspaceworkspace-data-apirefinitiv-dataplatform-eikon
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

10 Answers

Upvotes
Accepted
4.3k 2 4 5

Hi,

That sounds like a mismatch between Eikon API PRoxy and Eikon Desktop.

Could you :

  1. check Eikon Dekstop + REFINITIVHOLDINGS.EIKON.DATAAPIPROXY versions :
    (from Help about window)
  2. activate debug log in Eikon Desktop, restart Eikon, run your script and check in API Proxy log ?
    (all details on how to activate log and find file here)


1603114486393.png (38.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi,

my Desktop version is 4.0.53, my APIProxy version is 1.1.012. How can I update to the latest versions?

I activated the logs as suggested. But I can't find a log file starting with APIProxy in today's folders in \Thomson Reuters\Eikon Data\Logs\TRD\Eikon.20201019.154646.p19016\. There is just a single file (no folders) starting with EikonDM.

Upvotes
7.5k 10 6 8

@dfranzen Please could you try the solution on this thread and let us know how you get on. I hope this can help.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 0 0

Thank you for the quick response. Unfortunately, the problem persists. I downgraded httpx to verison 0.14.3 and nest-asyncio to version 1.3.3, as suggested in the thread. I restarted the kernel (I am using JupyterLab) and checked that the versions are correct.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
7.6k 15 6 9

@dfranzen

I'm using python 3.8.x with eikon lib 1.1.6.post3 and I can run the codes on Jupyter notebook (anaconda3) without the error. Not sure about the difference between your env and my env. But below is a list of library running by using !pip list under Jupyter notebook.

Package                            Version
---------------------------------- -------------------
absl-py                            0.10.0
alabaster                          0.7.12
anaconda-client                    1.7.2
anaconda-navigator                 1.9.12
anaconda-project                   0.8.3
appdirs                            1.4.4
argh                               0.26.2
asn1crypto                         1.3.0
astroid                            2.4.2
astropy                            4.0.1.post1
astunparse                         1.6.3
atomicwrites                       1.4.0
attrs                              19.3.0
autopep8                           1.5.3
Babel                              2.8.0
backcall                            0.2.0
backports.functools-lru-cache      1.6.1
backports.shutil-get-terminal-size 1.0.0
backports.tempfile                 1.0
backports.weakref                  1.0.post1
bcrypt                             3.1.7
beautifulsoup4                     4.9.1
bitarray                           1.4.0
bkcharts                           0.2
bleach                             3.1.5
bokeh                              2.1.1
boto                               2.49.0
Bottleneck                         1.3.2
brotlipy                           0.7.0
cachetools                         4.1.1
certifi                            2020.6.20
cffi                               1.14.0
chardet                            3.0.4
click                              7.1.2
cloudpickle                        1.5.0
clyent                             1.2.2
colorama                           0.4.3
colorlover                         0.3.0
comtypes                           1.1.7
conda                              4.8.3
conda-build                        3.18.11
conda-package-handling             1.7.0
conda-verify                       3.4.2
contextlib2                        0.6.0.post1
cryptography                       2.9.2
cufflinks                          0.17.3
cycler                             0.10.0
Cython                             0.29.21
cytoolz                            0.10.1
dask                               2.20.0
DatastreamDSWS                     1.0.7
DateTime                           4.3
decorator                           4.4.2
defusedxml                         0.6.0
deprecation                        2.1.0
diff-match-patch                   20200713
distributed                        2.20.0
docutils                           0.16
eikon                              1.1.6.post3
entrypoints                        0.3
et-xmlfile                         1.0.1
eventemitter                       0.2.0
fastcache                          1.1.0
filelock                           3.0.12
flake8                             3.8.3
Flask                              1.1.2
fsspec                             0.7.4
future                             0.18.2
gast                               0.3.3
gevent                             20.6.2
glob2                              0.7
gmpy2                              2.0.8
google-auth                        1.22.1
google-auth-oauthlib               0.4.1
google-pasta                       0.2.0
greenlet                           0.4.16
grpcio                             1.32.0
h11                                0.8.1
h2                                 3.2.0
h5py                               2.10.0
HeapDict                           1.0.1
hpack                              3.0.0
html5lib                           1.1
http3                              0.6.7
httpcore                           0.11.1
httpx                              0.15.5
hyperframe                         5.2.0
idna                               2.10
imageio                            2.9.0
imagesize                          1.2.0
importlib-metadata                 1.7.0
intervaltree                       3.0.2
ipykernel                          5.3.2
ipython                            7.16.1
ipython-genutils                   0.2.0
ipywidgets                         7.5.1
isort                              4.3.21
itsdangerous                       1.1.0
jdcal                              1.4.1
jedi                               0.17.1
Jinja2                             2.11.2
joblib                             0.16.0
json5                              0.9.5
jsonschema                         3.2.0
jupyter                            1.0.0
jupyter-client                     6.1.6
jupyter-console                    6.1.0
jupyter-core                       4.6.3
jupyterlab                         2.1.5
jupyterlab-server                  1.2.0
Keras                              2.4.3
keras-datasets                     0.1.0
Keras-Preprocessing                1.1.2
keyring                            21.2.1
kiwisolver                         1.2.0
lazy-object-proxy                  1.4.3
libarchive-c                       2.9
llvmlite                           0.33.0+1.g022ab0f
locket                             0.2.0
lxml                               4.5.2
Markdown                           3.2.2
MarkupSafe                         1.1.1
matplotlib                         3.2.2
mccabe                             0.6.1
menuinst                           1.4.16
mistune                            0.8.4
mkl-fft                            1.1.0
mkl-random                         1.1.1
mkl-service                        2.3.0
mock                               4.0.2
more-itertools                     8.4.0
mpmath                             1.1.0
msgpack                             1.0.0
multipledispatch                   0.6.0
navigator-updater                  0.2.1
nbconvert                          5.6.1
nbformat                           5.0.7
nest-asyncio                       1.4.0
networkx                           2.4
nltk                               3.5
nose                               1.3.7
notebook                           6.0.3
numba                              0.50.1
numexpr                            2.7.1
numpy                              1.18.5
numpydoc                           1.1.0
oauthlib                           3.1.0
olefile                            0.46
openpyxl                           3.0.4
opt-einsum                         3.3.0
packaging                          20.4
pandas                             1.0.5
pandocfilters                      1.4.2
paramiko                           2.7.1
parso                              0.7.0
partd                              1.1.0
path                               13.1.0
pathlib2                            2.3.5
pathtools                          0.1.2
patsy                              0.5.1
pep8                               1.7.1
pexpect                            4.8.0
pickleshare                        0.7.5
Pillow                             7.2.0
pip                                20.1.1
pkginfo                            1.5.0.1
plotly                             4.10.0
pluggy                             0.13.1
ply                                3.11
prometheus-client                  0.8.0
prompt-toolkit                     3.0.5
protobuf                           3.13.0
psutil                             5.7.0
py                                 1.9.0
pyasn1                             0.4.8
pyasn1-modules                     0.2.8
pycodestyle                        2.6.0
pycosat                            0.6.3
pycparser                          2.20
pycurl                             7.43.0.5
PyDatastream                       0.6.3
pydocstyle                         5.0.2
pyflakes                           2.2.0
Pygments                           2.6.1
pylint                             2.5.3
PyNaCl                             1.4.0
pyodbc                             4.0.0-unsupported
pyOpenSSL                           19.1.0
pyparsing                          2.4.7
pyreadline                         2.1
pyrsistent                         0.16.0
PySocks                            1.7.1
pytest                             5.4.3
python-configuration               0.7.1
python-dateutil                    2.8.1
python-jsonrpc-server              0.3.4
python-language-server             0.34.1
pytz                               2020.1
PyWavelets                         1.1.1
pywin32                            227
pywin32-ctypes                     0.2.0
pywinpty                           0.5.7
PyYAML                             5.3.1
pyzmq                              19.0.1
QDarkStyle                         2.8.1
QtAwesome                          0.7.2
qtconsole                          4.7.5
QtPy                               1.9.0
refinitiv-dataplatform             1.0.0a6
regex                              2020.6.8
requests                           2.24.0
requests-async                     0.6.2
requests-oauthlib                  1.3.0
retrying                           1.3.3
rfc3986                            1.4.0
rope                               0.17.0
rsa                                4.6
Rtree                              0.9.4
ruamel-yaml                        0.15.87
scikit-image                       0.16.2
scikit-learn                       0.23.1
scipy                              1.5.0
seaborn                            0.10.1
Send2Trash                         1.5.0
setuptools                         49.2.0.post20200714
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
sip                                4.19.13
six                                1.15.0
sniffio                            1.1.0
snowballstemmer                    2.0.0
sortedcollections                  1.2.1
sortedcontainers                   2.2.2
soupsieve                          2.0.1
Sphinx                             3.1.2
sphinxcontrib-applehelp            1.0.2
sphinxcontrib-devhelp              1.0.2
sphinxcontrib-htmlhelp             1.0.3
sphinxcontrib-jsmath               1.0.1
sphinxcontrib-qthelp               1.0.3
sphinxcontrib-serializinghtml      1.1.4
sphinxcontrib-websupport           1.2.3
spyder                             4.1.4
spyder-kernels                     1.9.2
SQLAlchemy                         1.3.18
statsmodels                        0.11.1
sympy                              1.6.1
tables                             3.6.1
tblib                               1.6.0
tensorboard                        2.3.0
tensorboard-plugin-wit             1.7.0
tensorflow                         2.3.1
tensorflow-estimator               2.3.0
termcolor                          1.1.0
terminado                          0.8.3
testpath                           0.4.4
threadpoolctl                      2.1.0
toml                               0.10.1
toolz                              0.10.0
tornado                            6.0.4
tqdm                               4.47.0
traitlets                          4.3.3
typing-extensions                  3.7.4.2
ujson                              1.35
unicodecsv                         0.14.1
urllib3                            1.25.9
watchdog                           0.10.3
wcwidth                            0.2.5
webencodings                       0.5.1
websocket-client                   0.57.0
Werkzeug                           1.0.1
wheel                              0.34.2
widgetsnbextension                 3.5.1
win-inet-pton                      1.1.0
win-unicode-console                0.5
wincertstore                       0.2
wrapt                              1.11.2
xlrd                               1.2.0
XlsxWriter                         1.2.9
xlwings                             0.19.5
xlwt                               1.3.0
xmltodict                          0.12.0
yapf                               0.30.0
zict                               2.0.0
zipp                               3.1.0
zope.event                         4.4
zope.interface                     4.7.1


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
7.5k 10 6 8

@dfranzen Please also refresh the eikon cache (Start => Thomson Reuters => Thomson Reuters Eikon Tools => Clear Cache). How are you getting on?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
49.7k 124 44 62

@dfranzen

If Clear Cache doesn't work, you can try to enable debug log in Eikon Data API by using the following code.

import logging
logger = logging.getLogger('pyeikon')
logger.setLevel(5) 

With the debug log, we should see the raw response sent by Eikon. For example:

2020-10-16 18:13:36,648 P[13500] [MainThread 20900] HTTP Response code: 200
2020-10-16 18:13:36,649 P[13500] [MainThread 20900] HTTP Response: {"timeseriesData":[{"dataPoints":[["2017-09-05T00:00:00Z",3.35,3.35,3.35,3.35,5],["2017-12-14T00:00:00Z",2.31,2.31,2.31,2.31,10],["2018-01-30T00:00:00Z",2.32,2.32,2.32,2.32,17],["2018-02-01T00:00:00Z",2.16,2.16,2.16,2.16,14],["2018-03-22T00:00:00Z",1.08,1.07,1.07,1.08,78],["2018-04-10T0
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 0 0

I cleared the cache and updated the Eikon package to version 1.1.7. Now the error messages are gone. But the request does not return anything :-(

I'll keep trying and keep you posted ...

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
4.3k 2 4 5

Hi,

It seems that the response content is wrongly formatted and causes error on decoding.

Could you send the full HTTP response extracted from the log (upload a *.txt file with your message) ?


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I set up a new "pure" native Python 3.8.5 environment with just pandas and eikon (1.1.7):

Package          Version
---------------- ---------
appdirs          1.4.4
certifi          2020.6.20
chardet          3.0.4
DateTime         4.3
deprecation      2.1.0
eikon            1.1.7
h11              0.9.0
httpcore         0.10.2
httpx            0.14.3
idna             2.10
nest-asyncio     1.3.3
numpy            1.19.2
packaging        20.4
pandas           1.1.3
pip              20.2.4
pyparsing        2.4.7
python-dateutil  2.8.1
pytz             2020.1
rfc3986          1.4.0
setuptools       50.3.2
six              1.15.0
sniffio          1.2.0
websocket-client 0.57.0
zope.interface   5.1.2

Next, I use the command line (no Jupyter notebook) to read the API key from the environment variables ( I double-checked that the key is correct, linked to my account and enabled):

ek.set_app_key(os.environ['EIKON_API_KEY'])

This seems to work fine (i.e. I do not receive an error message).

Now. when I do the following:

ek.get_timeseries('.STOXX50E', start_date='2018-10-01', end_date='2020-09-30')

I receive these error messages:

2020-10-19 11:10:02,012 P[10484] [MainThread 20964] Error code 401 | Client Error: Data API Proxy requires authentication.
2020-10-19 11:10:02,013 P[10484] [MainThread 20964] HTTP request failed: EikonError-Client Error: Data API Proxy requires authentication.
Upvotes
3 0 0 0

I tried again. And now it works. I don't know why (versions are the same as before).

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @dfranzen,

Just to review your issues, you reproduced 2 errors:

  • JSONDecodeError: this error could have different root causes between Eikon and the platform.
  • Data API Proxy requires authentication: that means that Eikon Desktop is running but is offline. Lastly, to fix it, you need to restart Eikon Desktop.

Now it works with same versions.
=> Did you restart Eikon after clearing the cache ?


Upvotes
3 0 0 0

The original issue was probably caused by incompatible versions. I assume that this has been fixed in Eikon 1.1.7.

The cause for the second problem is still unknown. The assumption that Eikon Desktop was offline is not correct.

I will close this issue anyway because I cannot reproduce the problem.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.