[Python] [ESI] 401 Error When Accessing ESI

Aha!

Swapped params to data in the requests.post() method and it worked (along with the b64 change). Thank you so much!

Edit: final version for anyone looking in the future:

def get_access_token():
    url = 'https://login.eveonline.com/v2/oauth/token'
    call_time = datetime.datetime.now()
    client_id = os.environ['CLIENT_ID']
    client_secret = os.environ['CLIENT_SECRET']
    response = requests.post(
        url,
        data={'grant_type':'refresh_token', 'refresh_token': os.environ['REFRESH_TOKEN']},
        headers={'Content-Type': 'application/x-www-form-urlencoded', 
                'Host':'login.eveonline.com'},
        auth=HTTPBasicAuth(client_id, client_secret))
    return response.content

This returns a JSON exactly as per the docs:

{
  "access_token":"MXP...tg2",
  "token_type":"Bearer",
  "expires_in":1200,
  "refresh_token":"gEy...fM0"
}
1 Like