【问题标题】:Why do I get an error from my API but only when I use some requests?为什么我的 API 会出现错误,但只有在我使用某些请求时才会出现错误?
【发布时间】:2022-01-19 11:40:02
【问题描述】:

我正在使用来自该站点 https://dev.whatismymmr.com 的 API,并且我想专门请求 closestRank,但我只得到一个 KeyError: 'ranked.closestRank'。但我可以获得整个 ['ranked'] 对象(其中包含 closestRank),但我最终得到了很多我不需要的信息。

我怎样才能得到最接近的排名?

我的代码

import requests 
LeagueName = input ("Summoner name")
base = ("https://eune.whatismymmr.com/api/v1/summoner?name=")
Thething = base + LeagueName
print (Thething)
response = requests.get(Thething)
print(response.status_code)
MMR = response.json()
print (MMR['ranked.closestRank'])

API 命令 <queue>.closestRank(队列是游戏模式,可以是普通排名) 您可以使用召唤师名称babada27进行测试。

【问题讨论】:

    标签: python api


    【解决方案1】:

    希望这是您正在寻找的 -
    将最后一行更改为

    print (MMR["ranked"]["closestRank"])
    

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-11
      • 2022-01-18
      • 2016-01-25
      相关资源
      最近更新 更多