String indices must be integers Giphy

44 Views Asked by At

I'm trying to get url from object data, but it isn't right. This program has stopped on line 4. Code is under.

My code:

    import requests

    gifs = str(requests.get("https://api.giphy.com/v1/gifs/random? 
    api_key=APIKEY"))
    dump = json.dumps(gifs)
    json.loads(dump['data']['url'])
1

There are 1 best solutions below

0
On

Your description is not clear enough. You expect to read a json and select a field that brings you something? I recommend you check this section of requests quickstart guide this i suspect you want to read the data to json and extract from some fields. Maybe something like this might help:

r = requests.get('http://whatever.com')  
url = r.json()['url']