# Connect in Rancher wth Python

**URL:** <https://forums.suse.com/t/connect-in-rancher-wth-python/41595>\
**Category:** SUSE Rancher Prime\
**Created:** [September 21, 2023, 3:06pm UTC](https://forums.suse.com/t/connect-in-rancher-wth-python/41595 "2023-09-21T15:06:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wesl\_wesl](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/wesl_wesl/32/10530_2.png) [@wesl\_wesl](https://forums.suse.com/u/wesl_wesl)\
**Post date:** [September 21, 2023, 3:06pm UTC](https://forums.suse.com/t/connect-in-rancher-wth-python/41595/1 "2023-09-21T15:06:23Z")

</div>

I’m trying to use this code to connect:

_import requests_

_# Setar tudo para o acesso_  
_endpoint = “[https://rancher.enterprise.com.br/v3](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.
