【问题标题】:python 'InlineResponse200' object is not subscriptablepython 'InlineResponse200' 对象不可下标
【发布时间】:2018-08-19 02:32:04
【问题描述】:
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打印。

谢谢!

【问题讨论】:

    标签: python object dictionary giphy


    【解决方案1】:

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

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

    不确定它是否是最好的方法,但它对我有用!

    【讨论】:

    • 你救了我一天!
    【解决方案2】:

    我来到这里是因为我看到这个使用的是一个大张旗鼓的自动生成的客户端。

    https://editor.swagger.io/

    用 .to_dict() 修复,它也可以在这里工作。

    【讨论】:

      猜你喜欢
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-11
      • 2021-12-14
      • 2023-03-20
      • 2015-07-31
      相关资源
      最近更新 更多