python'InlineResponse200'对象不可下标 [英] python 'InlineResponse200' object is not subscriptable

查看:218
本文介绍了python'InlineResponse200'对象不可下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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']

您好,我无法弄清楚如何将api_response(这是一个内联响应)转换为我可以操纵的内容(例如python字典).我需要找出一种保存或转换它的方法.我只能在atm上打印.

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.

谢谢!

推荐答案

我想出了一种提取数据的方法

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!

这篇关于python'InlineResponse200'对象不可下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆