# ESI refresh\_token

**URL:** <https://forums.eveonline.com/t/esi-refresh-token/477497>\
**Category:** Third Party Developers\
**Created:** [February 22, 2025, 2:04pm UTC](https://forums.eveonline.com/t/esi-refresh-token/477497 "2025-02-22T14:04:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andyriem\_Business](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/andyriem_business/32/433602_2.png) [@Andyriem\_Business](https://forums.eveonline.com/u/Andyriem_Business)\
**Post date:** [February 22, 2025, 2:04pm UTC](https://forums.eveonline.com/t/esi-refresh-token/477497/1 "2025-02-22T14:04:45Z")

</div>

I got an access token and a refresh token for the first time, but I cannot get a new access token from the refresh token.

```auto
def refresh_token(refresh_token):
    basic_auth = base64.urlsafe_b64encode(
        f"{client_id}:{client_secret}".encode("utf-8")
    ).decode()
    headers = {
        "Authorization": f"Basic {basic_auth}",
        "Content-Type": "application/x-www-form-urlencoded",
    }
    payload = {
        "grant_type": "refresh_token",
        "code": refresh_token,
    }
    response = requests.post(
        "https://login.eveonline.com/v2/oauth/token", headers=headers, data=payload
    )

    response.raise_for_status()

    return response.json()

```

---

<div class="post-metadata">

**Author:** ![Andyriem\_Business](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/andyriem_business/32/433602_2.png) [@Andyriem\_Business](https://forums.eveonline.com/u/Andyriem_Business)\
**Post date:** [February 22, 2025, 2:05pm UTC](https://forums.eveonline.com/t/esi-refresh-token/477497/2 "2025-02-22T14:05:34Z")

</div>

```auto
OUTPUT:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://login.eveonline.com/v2/oauth/token

```

---

<div class="post-metadata">

**Author:** ![Andyriem\_Business](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/andyriem_business/32/433602_2.png) [@Andyriem\_Business](https://forums.eveonline.com/u/Andyriem_Business)\
**Post date:** [February 22, 2025, 2:29pm UTC](https://forums.eveonline.com/t/esi-refresh-token/477497/3 "2025-02-22T14:29:47Z")

</div>

```auto
def refresh_token(refresh_token):
    basic_auth = base64.urlsafe_b64encode(
        f"{client_id}:{client_secret}".encode("utf-8")
    ).decode()
    headers = {
        "Authorization": f"Basic {basic_auth}",
        "Content-Type": "application/x-www-form-urlencoded",
    }
    payload = {
        "grant_type": "refresh_token",
        "refresh_token": refresh_token,
    }
    response = requests.post(
        "https://login.eveonline.com/v2/oauth/token", headers=headers, data=payload
    )

    response.raise_for_status()

    return response.json()

```

---

<div class="post-metadata">

**Author:** ![Gunner\_Garemoko](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gunner_garemoko/32/459924_2.png) [@Gunner\_Garemoko](https://forums.eveonline.com/u/Gunner_Garemoko)\
**Post date:** [May 9, 2025, 6:05am UTC](https://forums.eveonline.com/t/esi-refresh-token/477497/4 "2025-05-09T06:05:54Z")

</div>

```auto
payload = {
            "grant_type": "refresh_token",
            "refresh_token": token.refresh_token,
            "client_id": self.client_id,
            "client_secret": self.client_secret,
        }

        try:
            response = requests.post(self.token_endpoint, data=payload)

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/eveonline/original/3X/4/1/41ec4921cbaca7a6f9ea556e7cc20018461eae5e.png) [@system](https://forums.eveonline.com/u/system)\
**Post date:** [August 7, 2025, 6:06am UTC](https://forums.eveonline.com/t/esi-refresh-token/477497/5 "2025-08-07T06:06:38Z")

</div>

Closed on August 7, 2025, 6:06am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
