Hi There,
Hoping I could get some help with authentication. I’m pretty new to coding. As a bit of background:
I copied this approach (postman to get the refresh token) in Google sheets and still works today
I’m trying to build out further and I am trying to recreate the request in python (below)
I’m following the web app instructions, this is being built with Flask
def get_access_token():
url = 'https://login.eveonline.com/v2/oauth/token'
call_time = datetime.datetime.now()
response = requests.post(
url,
params={"grant_type":"refresh_token", 'refresh_token': os.environ['REFRESH_TOKEN']},
headers={'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic '+ os.environ['CLIENT_ID']+':'+os.environ['CLIENT_SECRET']}
)
# response.statuscode == 401 at this point
# below is moot, we dont get that far, I'm including it to show that
# I've been trying to update 'REFRESH_TOKEN' if they send
# a different one back
os.environ['TOKEN_EXPIRY'] = call_time + datetime.timedelta(seconds=response['expires_in'])
os.environ['REFRESH_TOKEN'] = response['refresh_token']
return response['access_token']
# --> TypeError: 'Response' object is not subscriptable
Excuse the abuse of os.environ for now please…
Anyone able to spot where I’m going wrong? Or is there something I can do to get a more descriptive error?
I have tried:
Adding and removing the 'Host':'login.eveonline.com' header
Removing the params parameter and constructing the url
hard-coding the keys/IDs instead of using system variables
Can you also share the response body you get back when it 401s? That will probably have some information in it that will narrow down the problem.
EDIT: You also need to base64 encode your client id and client secret as part of the Basic auth header. See Refreshing tokens | esi-docs. So that’s probably your problem.
I’ve also done a longer version which generates the auth string and then encodes in b64 and adds to the header, instead of using auth=HTTPBasicAuth(client_id, client_secret)), which throws the same error.