TypeError with json data in python -


i have simple python code using put ask price exchange, typeerror: unhashable type: 'dict' when trying run following code. not sure under how handle json data in python.

import requests  response = requests.get('https://bittrex.com/api/v1/public/getticker?market=btc-shibe') jdata = response.json()  assert response.status_code == 200  print jdata[{u'result':{u'ask'}}] 

you accessing resulting dictionary incorrectly. if wanted access asking price, use:

print jdata['result']['ask'] 

where 'result' gives nested dictionary, access value associated 'ask' on.

instead of using assertion, can ask response raise exception when there error response:

import requests  response = requests.get('https://bittrex.com/api/v1/public/getticker?market=btc-shibe') response.raise_for_status()  # raises exception if not 2xx or 3xx response  jdata = response.json()  print jdata['result']['ask'] 

you'd before tried access json data.

demo:

>>> import requests >>> response = requests.get('https://bittrex.com/api/v1/public/getticker?market=btc-shibe') >>> response.raise_for_status() >>> jdata = response.json() >>> print jdata['result']['ask'] 9.2e-07 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -