# ESI SSO Retrieving Access Token Server Error 500

**URL:** <https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514>\
**Category:** Third Party Developers\
**Created:** [April 8, 2018, 12:19pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514 "2018-04-08T12:19:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Lion](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/alexander_lion/32/65369_2.png) [@Alexander\_Lion](https://forums.eveonline.com/u/Alexander_Lion)\
**Post date:** [April 8, 2018, 12:19pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/1 "2018-04-08T12:19:46Z")

</div>

Hello There,

i am trying to get the ESI Authentification working on a Projekt. It is my first attempt too the ESI API.  
I am Programmierung in python. The generation of the _authCode_ via the link to the Eve Online authentification page is working but i cannot retrieve the access token via the python code provided here:

> **Python Code**
>
> ```
> SSO_ACCESS_TOKEN_URL = "https://login.eveonline.com/oauth/token"
> headers = {}
> headers['Content-Type'] = "application/json"
> headers['Authorization'] = "Basic " + base64(ClientID:ClientSecret)
> #headers['User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; W7) Gecko/20100101 Firefox/59.0"
> print("Header :" + str(headers))
> body ={}
> body['grant_type'] = "authorization_code"
> body['code'] = "_authCode_"
> print("Body :" + str(body))
> req = requests.post(SSO_ACCESS_TOKEN_URL, headers = headers, data = body)
> print ("Response from Server: " + str(req))
> print ("Response Headers from Server: " + str(req.headers))
> 
> ```

Everytime i get status 500 from the Server. If i try to get it via http instead of https its 404 Page not Found.  
i did the Step by Step instructions on the Eve Dev Blog for ESI API.

If i request a access token via the Auth.Link and pass this to the Server for getting the CharID it is working. But this is only a one time token for 20min and i want to get the refreshtoken aswell.

Any one here who can help me with this problem?

Alexander Lion

---

<div class="post-metadata">

**Author:** ![EveDataRules](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/evedatarules/32/52946_2.png) [@EveDataRules](https://forums.eveonline.com/u/EveDataRules)\
**Post date:** [April 8, 2018, 1:07pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/2 "2018-04-08T13:07:20Z")

</div>

Wrong content type; it should be. `Content-Type: application/x-www-form-urlencoded`

Also I highly recommend you use a library for OAuth2 instead of rolling your own, there is quite a bit to it that you would have to implement.

---

<div class="post-metadata">

**Author:** ![EveDataRules](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/evedatarules/32/52946_2.png) [@EveDataRules](https://forums.eveonline.com/u/EveDataRules)\
**Post date:** [April 8, 2018, 1:29pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/3 "2018-04-08T13:29:02Z")

</div>

This is popular for Python.  
[https://requests-oauthlib.readthedocs.io/en/latest/oauth2\_workflow.html#backend-application-flow](https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow)

---

<div class="post-metadata">

**Author:** ![Alexander\_Lion](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/alexander_lion/32/65369_2.png) [@Alexander\_Lion](https://forums.eveonline.com/u/Alexander_Lion)\
**Post date:** [April 8, 2018, 1:56pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/4 "2018-04-08T13:56:53Z")

</div>

Hello,

thanks for the hind. I took the Content-Type from the Step by Step tutorial:  
[Step-by-Step](https://developers.eveonline.com/blog/article/sso-to-authenticated-calls)

> To exchange the authorization code for an access token, we need to make a post request with curl.
> 
> The URL of the POST request has the following structure:
> 
> https://{login server base url}/oauth/token
> 
> In addition, the POST request needs headers and a body. We must send an Authorization header and a Content-Type header.
> 
> The Content-Type can be application/json or application/x-www-form-urlencoded. We’re going to use JSON.

Maybe CCP should fix this, so other people dont get the same problem.

> **Server Response**
>
> EveOnlineGetSSOToken()  
> Header :{‘content-type’: ‘application/x-www-form-urlencoded’, ‘authorization’: ‘Basic xxx’}  
> Body :{‘grant\_type’: ‘authorization\_code’, ‘code’: ‘_authCode_’}  
> Request Headers: {‘content-type’: ‘application/x-www-form-urlencoded’, ‘authorization’: ‘Basic xxx’, ‘Content-Length’: ‘100’}  
> Request Body: grant\_type=authorization\_code&code=_authCode_  
> Response from Server: \<Response [200]\>  
> Response Headers from Server: {‘Cache-Control’: ‘no-cache’, ‘Pragma’: ‘no-cache’, ‘Content-Type’: ‘application/json; charset=utf-8’, ‘Expires’: ‘-1’, ‘Server’: ‘Microsoft-IIS/8.5’, ‘Request-Context’: ‘appId=cid-v1:2ccf88f2-29b9-460a-bc15-7c0b79926f61’, ‘Date’: ‘Sun, 08 Apr 2018 13:45:48 GMT’, ‘Connection’: ‘close’, ‘Content-Length’: ‘209’}  
> Response Body from Server: {‘access\_token’: ‘someToken’, ‘token\_type’: ‘Bearer’, ‘expires\_in’: 1199, ‘refresh\_token’: ‘alsosomeToken’}

This worked fine now.  
Reguarding the OAuth2 Lib, i will see if it is more convinient. For testing the api the above function should do well. I want to learn how to do api programmieing and so on. If i take a ready made lib, the effect of learning ist less, than by doing steps and fall on the nkees. 😄  
But thank you very much anyway.

Alexander Lion

---

<div class="post-metadata">

**Author:** ![EveDataRules](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/evedatarules/32/52946_2.png) [@EveDataRules](https://forums.eveonline.com/u/EveDataRules)\
**Post date:** [April 8, 2018, 3:09pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/5 "2018-04-08T15:09:27Z")

</div>

Nice. If you are doing it to learn, keep on going.

Likely what happened is you said the content was JSON but passed URL encoded. Hence the 500 error when it tried to unmarshal the data.

---

<div class="post-metadata">

**Author:** ![DeODokktor](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/deodokktor/32/377131_2.png) [@DeODokktor](https://forums.eveonline.com/u/DeODokktor)\
**Post date:** [April 11, 2018, 3:45pm UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/6 "2018-04-11T15:45:46Z")

</div>

Have a look at [https://kyria.github.io/EsiPy/examples/sso\_login\_esipy/](https://kyria.github.io/EsiPy/examples/sso_login_esipy/) and see if that could work for you.

---

<div class="post-metadata">

**Author:** ![Alexander\_Lion](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/alexander_lion/32/65369_2.png) [@Alexander\_Lion](https://forums.eveonline.com/u/Alexander_Lion)\
**Post date:** [April 28, 2018, 9:22am UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/7 "2018-04-28T09:22:02Z")

</div>

Hello,

everything works fine now. I also managed to get the Accesscode directly into my Programm and fetching the caracter data.

Alexander Lion

---

<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:** [July 27, 2018, 9:22am UTC](https://forums.eveonline.com/t/esi-sso-retrieving-access-token-server-error-500/68514/8 "2018-07-27T09:22:04Z")

</div>

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