我尝试连接到 Riot api 以访问召唤者信息。我写了3个文件:
- “RiotConsts”:设置一些常量的文件,例如“URL”、“api_version”、“region”
- “RiotAPI”:主要功能
- “riot_main”:调用我想要的信息。
我收到一条错误消息:“RiotAPI' 对象没有属性 '_request'”。
class RiotAPI(object):
def __init__(self,api_key,region=Consts.REGIONS['europe_nordic_and_east']):
self.api_key = api_key
self.region = region
def request(self, api_key, params={}):
args = {'api_key': self.api_key}
for k,v in params.items():
if k not in args:
args[k] = v
response = requests.get(
Consts.URL['base'].format(
proxy = self.region,
region = self.region,
url = api_url
),
params=args
)
print (response.url)
return response.json()
def get_summoner_by_name(self, name):
api_url = Consts.URL['summoner_by_name'].format(
version=Consts.API_VERSIONS['summoner'],
summonerName=name
)
return self._request(api_url)
我希望收到召唤者信息,但我得到:'RiotAPI' 对象没有属性'_request'