Python throws an Attribute error
Question: I simply can't get my Code to work in python

it gives me this error:

    
    
    Traceback (most recent call last):
      File "C:/Users/Patrick/Desktop/SummonerGui/__main__.py", line 10, in <module>
        main()
      File "C:/Users/Patrick/Desktop/SummonerGui/__main__.py", line 6, in main
        r = api.get_summoner_by_name('ArcadeRuven')
    AttributeError: 'RiotAPI' object has no attribute 'get_summoner_by_name'
    

Here are my 3 files:

main.py

    
    
    from RiotAPI import RiotAPI
    
    
    def main():
        api = RiotAPI('API_KEY')
        r = api.get_summoner_by_name('ArcadeRuven')
        print r
    
    if __name__ == "__main__":
        main()
    

RiotAPI.py

    
    
    import requests
    import RiotConsts as Consts
    
    
    class RiotAPI(object):
    
        def __init__(self, api_key, region=Consts.REGIONS['europe_west']):
            self.api_key = api_key
            self.region = region
    
            def _requests(self, api_url, params={}):
                args = {'api_key': self.api_key}
                for key, value in params.items():
                    if key not in args:
                        args[key] = value
                response = requests.get(
                    Consts.URL['base'].format(
                        proxy=self.region,
                        region=self.region,
                        url=api_url
                        ),
                    params=args
                    )
                print response.url
                return respons.json()
    
            def get_summoner_by_name(self, name):
                api_url = Consts.URL['summoner_by_name'].format(
                    version=Consts.API_VERSIONS['summoner'],
                    names=name
                    )
                return self._request(api_url)
    

and here is the RiotConsts.py

    
    
    URL = {
        'base' : 'https://{proxy}.api.pvp.net/api/lol/{region}/{url}',
        'summoner_by_name' : 'v{version}/summoner/by-name/{names}'
        }
    
    API_VERSIONS = {
        'summoner' : '1.4'
        }
    
    REGIONS = {
        'europe_west' : 'euw'
        }
    

Why is there an AttributeError?? I thought that the attribute exists in
RiotAPI.py


Answer: The indentation of `get_summoner_by_name` and `_requests` is incorrect if you
want them to be methods of the object. They need to have the same level of
indentation as `__init__`.

Later in your code you have a call to `self._request` but the method is named
`_requests` (with a trailing "s").

