pseudonym117 / Riot-Watcher

Simple Python wrapper for the Riot Games API for League of Legends
MIT License
531 stars 150 forks source link

400/401 Client Error #201

Closed BANALW closed 2 years ago

BANALW commented 2 years ago

When I tried to use 'lol_watcher.match.matchlist_by_puuid' and 'lol_watcher.match.by_id' function, it reported that "HTTPError: 400 Client Error: Bad Request for url: ......". But my api works well at Riot developer page. Can't figure out where is the problem.

chamsom commented 2 years ago

Similar issue here, getting a Bad Request as well. @BANALW what does your Python look like?

matches = watcher.match.matchlist_by_puuid(region, name['puuid'])

name is currently storing a username on League. Unless, I have formatted wrong for the parameters? Please do let me know if you were able to make headway in resolving this issue somehow.

chamsom commented 2 years ago

@BANALW Found out the issue...so if you have a global variable for the region, I suggest not using it. If you do keep it, make sure within matches = watcher.match.matchlist_by_puuid(region, name['puuid']) you explicitly specify region = 'americas'. I had set a global variable region = na1 at the top of my code and as such, when passed as an argument to the parameter 'region' I received a 400/401 Request Error. This can be probably be closed now.

E.g. matches = watcher.match.matchlist_by_puuid(region ='americas', puuid = name['puuid']) This should return a list of matches.

BANALW commented 2 years ago

Thanks for the reply, I have tried the method you mentioned above, but I still get a 400/401 or 403 Error. My code is lol_watcher.match.matchlist_by_puuid('americas', '3cB0mJycwREAcSeVp5Yb35UhdvADtvHPHg2eQ0OEPGYkpfESiuq2GS0VUpCeMztYXWZVvnwp9PFONg'). Then I got a 403 error.

If I add region = ‘americas’, I got a positional argument follows keyword argument error.

chamsom commented 2 years ago

Apologies for the late reply, have you tried storing the username of interest in a variable called name?

For instance,

name = watcher.summoner.by_name(region, '[Put username here without braces]')

ranked_stats = watcher.league.by_summoner(region, name['id'])
print(ranked_stats)
print('\n')
ranked_solo_stats = ranked_stats[0]
hingston commented 2 years ago

Should RiotWatcher include mapping for regions na1-> americas? Or alternatively renaming the region argument here to make it clearer there's a difference?

liadT22 commented 2 years ago

The issue is that in other function region is represented as "eun1/na1...etc" but in this fucntion the region is expected to be "EUROPE/AMERICA/ASIA"

Josde commented 2 years ago

Should RiotWatcher include mapping for regions na1-> americas? Or alternatively renaming the region argument here to make it clearer there's a difference?

I guess an automatic mapping would be the best way to go, since AFAIK this is the only function that use these region names.
By the way, in case someone finds this useful: As far as I'm seeing with my tests, Turkish and Russian API endpoints are grouped into "EUROPE", and Oceania is for some reason grouped into "AMERICAS". Other regions follow logic and geography.

hingston commented 2 years ago

The AMERICAS routing value serves NA, BR, LAN, LAS, and OCE. The ASIA routing value serves KR and JP. The EUROPE routing value serves EUNE, EUW, TR, and RU.

From https://developer.riotgames.com/apis#match-v5

I think an automatic mapping should be implemented. Otherwise, developers will all have to implement their own.

Justin-Isler commented 2 years ago

Hey guys! I am currently having a similar issue.

my_matches = watcher.match.matchlist_by_puuid(my_region, me['puuid']) print(my_matches)

'me' is storing my summoner info called by watcher.summoner.by_name

I had no issues getting this to run with v4, but v5 is truly proving to be the headache to work around.

Silver15987 commented 2 years ago

had the same issue, noticed that the API has different variables for the regions in match history for some reason. For 'euw1' it is europe, while for 'na1' it's americas.

pseudonym117 commented 2 years ago

For error codes:

400:

If you're getting this message, you've most likely entered an incorrect Summoner or Account ID. The most common cause is using an ID that does not belong to the API key you are currently using. It could also be caused by a poorly formed ID.

401:

This error indicates that the request being made did not contain the necessary authentication credentials (e.g., an API key) and therefore the client was denied access. Most likely cause is an API key has not been provided.

403:

possible causes:

Its possible that a remapper could be added to correct match endpoints. This hasnt been done historically because if riot decides to add a new region, a new version of riotwatcher will need to be published with an updated mapping. This unfortunately may be the best solution though... will look into feasibility.