Python Forum
JSON TypeError: list indices must be integers, not str
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSON TypeError: list indices must be integers, not str
#1
Hello, Sorry for disturbing you but I need some help with my code.

I am trying to list all crypto currencies with a Base Volume > 200.
When I try to browse the volume I get an error list indices must be integers, not str
I don't understand what's the error could be because because I put a [0] so it's an integer not a str

Many thanks in advance for all your answers

Best regards
import sys, signal, json, time
from bittrex import bittrex
import urllib
import urllib2

api = bittrex(KEY, SECRET)
def coin_in_list():
	currencies = api.getcurrencies()
	coins = []
	a = 0
	for i in currencies:
		coins.append(i["Currency"])	
		a = a+1
	return coins
	
def volume_checker(coins):
	for i in coins:
		if i != 'BTC':
			market = "BTC-" + i
			marketsummary = api.getmarketsummary(market)
			volume_str = marketsummary[0]['BaseVolume']
			volume = float(volume_str)
			if volume >=200:
				print i

print volume_checker(coin_in_list())
And the bittrex lib

#!/usr/bin/env python
import urllib
import urllib2
import json
import time
import hmac
import hashlib

class bittrex(object):
    
    def __init__(self, key, secret):
        self.key = key
        self.secret = secret
        self.public = ['getmarkets', 'getcurrencies', 'getticker', 'getmarketsummaries', 'getmarketsummary', 'getorderbook', 'getmarkethistory', 'GetTicks']
        self.market = ['buylimit', 'buymarket', 'selllimit', 'sellmarket', 'cancel', 'getopenorders']
        self.account = ['getbalances', 'getbalance', 'getdepositaddress', 'withdraw', 'getorder', 'getorderhistory', 'getwithdrawalhistory', 'getdeposithistory']
    
    
    def query(self, method, values={}):
        if method in self.public:
            url = 'https://bittrex.com/api/v1.1/public/'
        elif method in self.market:
            url = 'https://bittrex.com/api/v1.1/market/'
        elif method in self.account: 
            url = 'https://bittrex.com/api/v1.1/account/'
        else:
            return 'Something went wrong, sorry.'
        
        url += method + '?' + urllib.urlencode(values)
        
        if method not in self.public:
            url += '&apikey=' + self.key
            url += '&nonce=' + str(int(time.time()))
            signature = hmac.new(self.secret, url, hashlib.sha512).hexdigest()
            headers = {'apisign': signature}
        else:
            headers = {}
        
        req = urllib2.Request(url, headers=headers)
        response = json.loads(urllib2.urlopen(req).read())
        
        if response["result"]:
            return response["result"]
        else:
            return response["message"]

			
    def query2(self, method, values={}):
        if method in self.public:
            url = 'https://bittrex.com/Api/v2.0/pub/market/'
        else:
            return 'Something went wrong, sorry.'
        
        url += method + '?' + urllib.urlencode(values)
        
        if method not in self.public:
            url += '&apikey=' + self.key
            url += '&nonce=' + str(int(time.time()))
            signature = hmac.new(self.secret, url, hashlib.sha512).hexdigest()
            headers = {'apisign': signature}
        else:
            headers = {}
        
        req = urllib2.Request(url, headers=headers)
        response = json.loads(urllib2.urlopen(req).read())
        
        if response["result"]:
            return response["result"]
        else:
            return response["message"]
    
    
    def getmarkets(self):
        return self.query('getmarkets')
    
    def getcurrencies(self):
        return self.query('getcurrencies')
    
    def getticker(self, market):
        return self.query('getticker', {'market': market})

    def get_historical_data(self, market, unit):
        return self.query2('GetTicks', {'marketName': market, 'tickInterval': unit})		
    
    def getmarketsummaries(self):
        return self.query('getmarketsummaries')
    
    def getmarketsummary(self, market):
        return self.query('getmarketsummary', {'market': market})
    
    def getorderbook(self, market, type, depth=20):
        return self.query('getorderbook', {'market': market, 'type': type, 'depth': depth})
    
    def getmarkethistory(self, market, count=20):
        return self.query('getmarkethistory', {'market': market, 'count': count})
    
    def buylimit(self, market, quantity, rate):
        return self.query('buylimit', {'market': market, 'quantity': quantity, 'rate': rate})
    
    def buymarket(self, market, quantity):
        return self.query('buymarket', {'market': market, 'quantity': quantity})
    
    def selllimit(self, market, quantity, rate):
        return self.query('selllimit', {'market': market, 'quantity': quantity, 'rate': rate})
    
    def sellmarket(self, market, quantity):
        return self.query('sellmarket', {'market': market, 'quantity': quantity})
    
    def cancel(self, uuid):
        return self.query('cancel', {'uuid': uuid})
    
    def getopenorders(self, market):
        return self.query('getopenorders', {'market': market})
    	
    def getopenorders_special(self):
        return self.query('getopenorders')
		
    def getbalances(self):
        return self.query('getbalances')
    
    def getbalance(self, currency):
        return self.query('getbalance', {'currency': currency})
    
    def getdepositaddress(self, currency):
        return self.query('getdepositaddress', {'currency': currency})
    
    def withdraw(self, currency, quantity, address):
        return self.query('withdraw', {'currency': currency, 'quantity': quantity, 'address': address})
    
    def getorder(self, uuid):
        return self.query('getorder', {'uuid': uuid})
    
    def getorderhistory(self, market, count):
        return self.query('getorderhistory', {'market': market, 'count': count})
    
    def getwithdrawalhistory(self, currency, count):
        return self.query('getwithdrawalhistory', {'currency': currency, 'count': count})
    
    def getdeposithistory(self, currency, count):
        return self.query('getdeposithistory', {'currency': currency, 'count': count})
Reply
#2
Could you run again and post the complete error traceback. It contains very important information
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: string indices must be integers, not 'str' LEMA 2 224 Jun-12-2024, 09:32 PM
Last Post: LEMA
  tuple indices must be integers or slices, not str cybertooth 16 12,560 Nov-02-2023, 01:20 PM
Last Post: brewer32
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,434 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,603 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,863 Mar-24-2023, 08:34 AM
Last Post: fullytotal
Question How to append integers from file to list? Milan 8 1,679 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 2,286 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error "list indices must be integers or slices, not str" dee 2 1,722 Dec-30-2022, 05:38 PM
Last Post: dee
  TypeError: string indices must be integers JonWayn 12 3,807 Aug-31-2022, 03:29 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 4,140 Aug-11-2022, 08:23 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020