PandaXcentric / game_apis

This repository is for integrating with different apis to allow you to pull player or game data
MIT License
28 stars 2 forks source link

config.yml #7

Closed OHR7 closed 5 years ago

OHR7 commented 5 years ago

The config.yml is missing and there is no info on how to create or get one

PandaXcentric commented 5 years ago

Hey, I've put the config file in the .gitignore so I don't accidentally commit my private keys, I'm adding an example of the config.yaml to the readme. Let me know if it's still confusing though and I'll try to add more documentation.

Also, by default we look for "config.yaml" in that directory (you have config.yml, which will work if you explicitly pass that name when creating the class, but won't get picked up by default).

PandaXcentric commented 5 years ago

just pushed the documentation change, let me know if I can close this issue.

OHR7 commented 5 years ago

I get Key Error for (key_secret)in this part of code

# api.py line 22
self.key_id = data[self.ID.lower()]['key_id']
self.key_secret = data[self.ID.lower()]['key_secret']
if 'key_passphrase' in data[self.ID.lower()]:
    self.key_passphrase = data[self.ID.lower()]['key_passphrase']

so the example config.yaml is missing key_secret in the riot page doesnt give me any key_secret just the API-key screen shot 2018-12-19 at 4 39 29 pm

maybe the api-key is the key_secret but then what is key_id, is not clear

also how do you get the riotesports key I dont see any link in riot dev page?


opendota:
  key_id: null
riot:
  key_id: my-riot key
pubg:
  key_id: null
egb:
  key_id: null
  key_secret: null
riotesports:
  key_id: null```
PandaXcentric commented 5 years ago

Hey, so not everything needs an api key, so you should only need the fields if they're required for the class you're loading. I just ran the unit tests for both riot apis and open_dota and they all passed. Can you send me the full stack trace you're getting? I don't know why it'd work fine for me but give you a key error. As a quick fix, just adding "key_secret: null" to the rest of the config should fix the problem.

Also, riotesports isn't an api from riot, so it isn't in their dev page or documents. I hit rest routes that a website who gives stats on pro matches made for themselves to get info from pro games. It's a bit tricky to use, but has tons of good data.

smstojanovic commented 5 years ago

Just as a safeguard for the prospect of potentially needing both a key_secret and key_passphrase I think the key secret should be wrapped in a conditional, similar to key_passphrase. (api.py lines 23-25)

However, not having a secret key in the config should not pose a problem.

Additionally, If you want to experiment with config files, setting the "local_config" parameter to True will allow you to use this library and point to a config file in the root of your current workflow.

Please advise whether this solves your issue.

PandaXcentric commented 5 years ago

Hey, I didn't think to check, but are you using python 2 or python 3? This api was written for python 3 and tested on python 3.6. I don't know if maybe that could account for your issue

OHR7 commented 5 years ago
(venv) Omars-MacBook-Pro:scrappy omar$ python riot_api_ex.py 
<class 'KeyError'>
<class 'KeyError'>
<class 'KeyError'>
2018-12-21 10:19:28,009 : ERROR : RIOT: Status code 403
2018-12-21 10:19:28,009 : ERROR : RIOT: Status code 403
2018-12-21 10:19:28,009 : ERROR : RIOT: Status code 403
2018-12-21 10:19:28,009 : ERROR : RIOT: Status code 403
2018-12-21 10:19:28,010 : ERROR : RIOT: Headers: {'Content-Type': 'application/json;charset=utf-8', 'Date': 'Fri, 21 Dec 2018  18:19:28 GMT', 'Content-Length': '52', 'Connection': 'keep-alive'}
2018-12-21 10:19:28,010 : ERROR : RIOT: Headers: {'Content-Type': 'application/json;charset=utf-8', 'Date': 'Fri, 21 Dec 2018  18:19:28 GMT', 'Content-Length': '52', 'Connection': 'keep-alive'}
2018-12-21 10:19:28,010 : ERROR : RIOT: Headers: {'Content-Type': 'application/json;charset=utf-8', 'Date': 'Fri, 21 Dec 2018  18:19:28 GMT', 'Content-Length': '52', 'Connection': 'keep-alive'}
2018-12-21 10:19:28,010 : ERROR : RIOT: Headers: {'Content-Type': 'application/json;charset=utf-8', 'Date': 'Fri, 21 Dec 2018  18:19:28 GMT', 'Content-Length': '52', 'Connection': 'keep-alive'}
2018-12-21 10:19:28,010 : ERROR : RIOT: Resp: {"status":{"message":"Forbidden","status_code":403}}
2018-12-21 10:19:28,010 : ERROR : RIOT: Resp: {"status":{"message":"Forbidden","status_code":403}}
2018-12-21 10:19:28,010 : ERROR : RIOT: Resp: {"status":{"message":"Forbidden","status_code":403}}
2018-12-21 10:19:28,010 : ERROR : RIOT: Resp: {"status":{"message":"Forbidden","status_code":403}}
Traceback (most recent call last):
  File "riot_api_ex.py", line 4, in <module>
    hello = riot.hello_world()
  File "/Users/omar/PycharmProjects/scrappy/venv/lib/python3.7/site-packages/game_apis/rest/riot.py", line 48, in hello_world
    return self._get("/lol/summoner/v3/summoners/by-name/RiotSchmick")
  File "/Users/omar/PycharmProjects/scrappy/venv/lib/python3.7/site-packages/game_apis/rest/riot.py", line 43, in _get
    resp.raise_for_status()
  File "/Users/omar/PycharmProjects/scrappy/venv/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://na1.api.riotgames.com/lol/summoner/v3/summoners/by-name/RiotSchmick?api_key=RGAPI-ab3bb07a-6028-....

this my script:

from game_apis.rest import Rest

riot = Rest('config.yaml', local_config=True).Riot
hello = riot.hello_world()

im using python3 (Python 3.7.1 (default, Oct 30 2018, 15:57:57)) my conf file

opendota:
  key_id: null
riot:
  key_id: secret_key(obviosly not showing here)
  key_secret: null # added this still not working
pubg:
  key_id: null
egb:
  key_id: null
  key_secret: null
riotesports:
  key_id: null
OHR7 commented 5 years ago

added tracebak print

<class 'KeyError'>
Traceback (most recent call last):
  File "/Users/omar/PycharmProjects/scrappy/venv/lib/python3.7/site-packages/game_apis/rest/api.py", line 24, in __init__
    self.key_secret = data[self.ID.lower()]['key_secret']
KeyError: 'key_secret'
OHR7 commented 5 years ago

weird I tried the link directly and worked on the browser so something is wrong with api requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://na1.api.riotgames.com/lol/summoner/v3/summoners/by-name/RiotSchmick?api_key=RGAPI-ab3bb07a-6028-....

OHR7 commented 5 years ago

Ok so I fixed the error by commenting out the self.key_secret = data[self.ID.lower()]['key_secret'] line so maybe you need to add the if so won't raise any errors after that can be closed PD what is the page that you use for riot esports? thanks

PandaXcentric commented 5 years ago

we added the guard against it, seems like this is a python 3.7 specific issue...I'm going to close this issue. Feel free to open a new one if the problem persists or you run into anything else!