Forums

API Requests stopped working for no reason

Hello everybody, since tonight i get the following error message:

Traceback (
most recent call last):
  File "/home/TomburgCapital/MeanReversionAlgoSL.py", line 48, in <module>
    coinprice = coinprice.json()
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.10/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Even though i didn't touch my code nor installed or changed any modules. I can't figure out the problem here. Can anybody help?

Code:

    coinprice = requests.get(f'https://api.bybit.com/v5/market/kline?category=linear&symbol={asset}&interval=60')
   **line 48-->** coinprice = coinprice.json()
    pc = pd.DataFrame(reversed(coinprice['result']['list']))
    pc = pc.set_axis(['time','open','high','low','close','volume', 'turnover'],axis = 'columns')
    pc = pc.as 
type(float)

[edit by admin for formatting]

The errors is saying that what ever is coming back from your api call is not well formatted json. Maybe add some temporary logging to see what youre getting back

The API works fine offline in my anaconda environment weirdly. The data I get looks like it looked before too so I’m not sure what happened since I didn’t even touch the code or anything in my scheduled task.

Has anybody any idea how to sole this problem? I still couldn't figure it out. Thanks

Could you check the HTTP status code of the response before you call coinprice.json()?