0

Using Twitch's API I am trying to make the results from the JSON into an array (I think that's what it's called?) I get this come up in the console:

Error Raised: (<class 'KeyError'>, KeyError(0,), <traceback object at 0x04520DA0>)

And here's the code that defines it all

    r = requests.get('https://api.twitch.tv/kraken/channels/runnerbeany'.format(query))
    dat = r.json()
    dat = dat[0]
    data = []
    data.append(dat['display_name'])
    data.append(dat['followers'])
    data.append(dat['game'])
    data.append(dat['logo'])
    data.append(dat['status'])
    data.append(dat['url'])

1 Answer 1

1

you are re-initializing dat = dat[0], rename it with first_dat = dat[0]

    r = requests.get('https://api.twitch.tv/kraken/channels/runnerbeany'.format(query))
    dat = r.json()
    print dat
    first_dat = dat[0]
    data = []
    data.append(dat['display_name'])
    data.append(dat['followers'])
    data.append(dat['game'])
    data.append(dat['logo'])
    data.append(dat['status'])
    data.append(dat['url'])
Sign up to request clarification or add additional context in comments.

3 Comments

So I just remove dat = r.json() or dat = dat[0]?
change dat = dat[0] to first_dat = dat[0]
edit: thanks for that change - just working out this last error now but thanks for helping! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.