Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Trakt Problem #685

Open
nequam opened this issue May 15, 2024 · 2 comments
Open

Trakt Problem #685

nequam opened this issue May 15, 2024 · 2 comments

Comments

@nequam
Copy link

nequam commented May 15, 2024

I had a problem with the oauth for trakt. I am NOT a python developer, mostly deal with C# and backend code.

I fixed part of it by changing the post function in the trakt.py in content/services by changing the headers when it's getting a code versus when it's just talking to trakt.

There is python library for trakt I'll check later if this is what the problem was.

@nequam
Copy link
Author

nequam commented May 15, 2024

I just corrected the part where it gets a token, not where it was complaining continually that I need to add the user back again. I can't test that until I rebuild the docker container and push that to the machines that run things.

It was fun tracking it down and I learned a bit about python.

@nequam
Copy link
Author

nequam commented May 15, 2024

The change fixed it, it now works perfectly. :)

This is the change that I made to /content/services/trakt.py

Starting around line 159, replaced the post and the oauth functions.


def post(url, data, auth=False):
    try:
        if auth:
            headers = {
                'Content-type': "application/json"
            }
        else:
            headers={
                'Content-type': "application/json", "trakt-api-key": client_id, "trakt-api-version": "2",
                "Authorization": "Bearer " + current_user[1]}
        response = session.post(url, headers=headers, data=data)
        logerror(response)
        response = json.loads(response.content, object_hook=lambda d: SimpleNamespace(**d))
        time.sleep(1.1)
    except:
        response = None
    return response


def oauth(code=""):
    if code == "":
        response = post(url='https://api.trakt.tv/oauth/device/code', data=json.dumps({'client_id': client_id}), auth=True)
        if not response is None:
            return response.device_code, response.user_code
        else:
            print("trakt.tv could not be reached right now! Please try again later. The script will most likely exit after this message.")
            time.sleep(5)
    else:
        response = None
        while response is None:
            response = post(url='https://api.trakt.tv/oauth/device/token', data=json.dumps(
                {'code': code, 'client_id': client_id, 'client_secret': client_secret}),auth=True)
            time.sleep(1)
        return response.access_token

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

No branches or pull requests

1 participant