Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to make calls with Python requests #22

Closed
dmilin1 opened this issue Dec 4, 2018 · 2 comments
Closed

Trying to make calls with Python requests #22

dmilin1 opened this issue Dec 4, 2018 · 2 comments

Comments

@dmilin1
Copy link

dmilin1 commented Dec 4, 2018

I currently have this code:

import requests

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic cmlvdDp4MFVua3NrcFMzSUlaTkd6TVlaaVNn',
}

res = requests.get('https://127.0.0.1:52351/lol-champ-select/v1/session', headers=headers)

print(res.json())

My problem is that no matter what I do, I'm getting this error:

Traceback (most recent call last):
  File "clientTest.py", line 8, in <module>
    res = requests.get('https://127.0.0.1:52351/lol-champ-select/v1/session', headers=headers)
  File "C:\Users\Dimitrie\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\Dimitrie\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Dimitrie\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Dimitrie\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Dimitrie\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='127.0.0.1', port=52351): Max retries exceeded with url: /lol-champ-select/v1/session (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)'),))

Clearly I'm doing something wrong, however I'm not quite sure what the problem is. It sounds like there is something wrong with my authentication token I copied and pasted out of Rift Explorer. However, I'm not really sure what the role of this token is considering everything is handled over localhost. I'm also not sure how to acquire this token. Could anyone offer some help?

Edit: Okay, so it turns out my problem was SSL verification built into python's requests library. I fixed it by changing the request line to this:
res = requests.get('https://127.0.0.1:52351/lol-champ-select/v1/session', headers=headers, verify=False)

However, I still have no idea how to get my Authorization key and the randomized port after the client starts. How do I do that?

Edit 2:

Wow so this was absurdly complicated to figure out. Doesn't help that there is no documentation anywhere. Here's how I solved it:

When the League Client starts, a file called "lockfile" is generated in the League of Legends install directory. The file looks something like this:

LeagueClient:9872:52351:x0UnkskpS3IIZNGzMYZiSg:https

In my case, 52351 is the port. To find the authentication token, you must take "x0UnkskpS3IIZNGzMYZiSg" and concatenate it with "riot:" with the riot part first. Like this:

"riot:x0UnkskpS3IIZNGzMYZiSg"

You then need to take this string and encode it. Then you must take that encoding and turn it into base 64 as a string. That finally is your authentication token. This is the code I used to compute it in python.

merged = "riot:" + "x0UnkskpS3IIZNGzMYZiSg"
authToken = base64.b64encode(merged.encode())

I hope this helps someone else because it took me a good few hours of struggling.

@dmilin1 dmilin1 closed this as completed Dec 5, 2018
@Pupix
Copy link
Owner

Pupix commented Dec 5, 2018

Your first error has nothing to do with the edit you added.

The first error is happening because the certificate is self-signed and python can't validate it (as the error message suggests). I solved it in Rift Explorer with this

app.commandLine.appendSwitch('--ignore-certificate-errors');

For the edits you added the solution was here

const header = `Basic ${btoa(`${username}:${password}`)}`;

@dmilin1
Copy link
Author

dmilin1 commented Dec 5, 2018

Thanks for the response and an even bigger thanks for Rift Explorer. It's really nice to have such a convenient way to explore the relatively undocumented Client API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants