hitbtc-com / hitbtc-api

HitBTC API
GNU Lesser General Public License v3.0
322 stars 152 forks source link

Problem with GET /api/2/public/ticker/{symbol} method #150

Open rudeBo opened 6 years ago

rudeBo commented 6 years ago

I am currently using the method GET /api/2/public/ticker/{symbol} to get the current price of a coin. below is my mothod:-

import sys, getopt import uuid import time import requests from decimal import *

class hitbtc(object): def init(self,public_key, secret): self.url = "https://api.hitbtc.com/api/2" self.session = requests.session() self.session.auth = (public_key, secret)

def get_price(self, symbol_code):
    """Get symbol price."""
    return self.session.get("%s/public/ticker/%s" % (self.url, symbol_code)).json()

The code works for some time then i get the following error in my get_price method:-

Traceback (most recent call last): File "live.py", line 64, in main(sys.argv[1:]) File "live.py", line 47, in main developingCandlestick.tick(chart.getCurrentPrice(exchange)) File "C:\Users\rudeBo\Desktop\python code\Bot1_HitBtc_LTC\part 3\botchart.py", line 51, in getCurrentPrice currentValues = self.conn.api_query("returnTicker",self.pair) File "C:\Users\rudeBo\Desktop\python code\Bot1_HitBtc_LTC\part 3\hitbtc.py", line 34, in api_query return self.get_price(symbol_code) File "C:\Users\rudeBo\Desktop\python code\Bot1_HitBtc_LTC\part 3\hitbtc.py", line 16, in get_price return self.session.get("%s/public/ticker/%s" % (self.url, symbol_code)).json() File "C:\Python36\lib\site-packages\requests\models.py", line 892, in json return complexjson.loads(self.text, **kwargs) File "C:\Python36\lib\json__init__.py", line 354, in loads return _default_decoder.decode(s) File "C:\Python36\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python36\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Can anyone help me with this?

Thanks

fujiapple852 commented 6 years ago
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

You are clearly receiving a non-json response which causes this error. Print out the raw response before attempting to parse it and it should be clear what the error is.