python 'InlineResponse200' object is not subscriptable

北城余情 提交于 2020-06-28 04:05:30

问题


import time
import giphy_client
from giphy_client.rest import ApiException
from pprint import pprint

# create an instance of the API class
api_instance = giphy_client.DefaultApi()
api_key = 'dc6zaTOxFJmzC' # str | Giphy API Key.
q = 'cheeseburgers' # str | Search query term or prhase.
limit = 1 # int | The maximum number of records to return. (optional) (default to 25)
offset = 0 # int | An optional results offset. Defaults to 0. (optional) (default to 0)
rating = 'g' # str | Filters results by specified rating. (optional)
lang = 'en' # str | Specify default country for regional content; use a 2-letter ISO 639-1 country code. See list of supported languages <a href = \"../language-support\">here</a>. (optional)
fmt = 'json' # str | Used to indicate the expected response format. Default is Json. (optional) (default to json)

try: 
    # Search Endpoint
    api_response = api_instance.gifs_search_get(api_key, q, limit=limit, offset=offset, lang=lang, fmt=fmt)
    #pprint(api_response)
except ApiException as e:
    print("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)

api_response['data']

Hello, I cant figure out how to convert api_response, which is a inline response, to something that I can manipulate such as a python dictionary. I need to figure out a way to save or convert it. I can only print it atm.

Thanks!


回答1:


I figured out a way to extract the data

x = api_response.data
y = x[0]
y.images.downsized.url

Not sure if its the best method but it works for me!



来源:https://stackoverflow.com/questions/49212062/python-inlineresponse200-object-is-not-subscriptable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!