Connect in Rancher wth Python

I’m trying to use this code to connect:

import requests

# Setar tudo para o acesso
endpoint = “https://rancher.enterprise.com.br/v3

access_key = “token-aaaaa”
secret_key = aaaaayyyyyaaaaayyyyyaaaayyy"

bearer_token = f"{access_key}:{secret_key}"

Setar o cabeçalho

headers = {
“Authorization”: f"Bearer {bearer_token}"
}

# Fazer a request
url = f"{endpoint}"
response = requests.get(url,

  •                    headers = headers)*
    

# Printar o resultado da request
if response.status_code == 200:

  • data = response.json()*
  • print(data)*
    else:
  • print(f"Error: {response.status_code} - {response.text}")*

But I always receive this error:

{“type”:“error”,“status”:“401”,“message”:“Unauthorized 401: must authenticate”}

I don’t know why I always receive this error, because i’m sure how the “access_key” and the “secret_key” are right.

What can I do to fix it? I have no idea.