Jump to content
Guest074076

LogOn Get Session token error 500

Recommended Posts

I am getting an error when attempting to LogOn and obtain a session token.  The error from my POST request is error 500 Server Error.
 
Here is my python code:
 
 
headers = {'target':'session',
                  'uriTemplate':'/',
                  'transport':'POST',
                  'envelope':'JSON',
                  'Content-Type':'application/json'}
data = {"Password":"<hidden>",
            "UserName":"<hidden>",
            "AppKey":"<hidden>"}
r = requests.post(url = url, headers = headers, data = data)
print r.text
{"HttpStatus":500,"ErrorMessage":"Server error","ErrorCode":500}
 
I confirmed with APISupport that my account is enabled for Live trading, so the account is not the issue.
 
Is there something I'm missing?

Share this post


Link to post

Hello,

It appears that since you have added session/ to your URL, then you are targeting it twice since you have also included session and the uriTemplate / in your header too. Probably means the server is trying to resolve the call to a faulty address.

Either remove session/ from the URL or from the header should resolve the problem.

Kind Regards, PM
  

Share this post


Link to post
I removed session from the url and I am getting
print r.text
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Ajax Test Harness</title>
    <link href="/TradingApi/Content/css?v=DIeV9tErqsXMXdK_zhXBay_u2zQ2TZi6am7tIyxAp6Y1" rel="stylesheet" type="text/css" />
    <link href="/TradingApi/Content/themes/base/css?v=ps9Ga9601PrzNA2SK3sQXlYmNW3igUv5FOdOPWptyus1" rel="stylesheet" type="text/css" />
    <script></script>
</head>
    <body>
        <div style="width: 100%; margin: 0px;">
            <img alt="Gain|Capital Logo" src="/TradingApi/Images/Gain Logo White.png"/>
        </div>

<script src="/TradingApi/Scripts/tradingApi.js" language="javascript" type="text/javascript"></script>
<script src="/TradingApi/Scripts/corsTest.js" language="javascript" type="text/javascript"></script>
<script src="/TradingApi/Scripts/json2.js" language="javascript" type="text/javascript"></script>
<div id="apitest" style="padding: 10px; height: 100%">
    <h2>Ajax Test Harness</h2>
    <form id="form1" runat="server"></form>
    <hr />Script<br/>
    <textarea id="code" style="min-height: 300px; width: 100%">
        var userName = "<hidden>";
        doPost('/session',{ "UserName": userName, "Password": "password"}, function (data, textCode) {
            // Smoke Test
            doGet('/smoketest');
            setRequestHeader("UserName", userName);
            setRequestHeader("Session", data.Session);
            // Authentication Test
            doGet('/smoketest/authenticated');
            // Account Information Tests
            doGet('/useraccount/<hidden>/ChartingEnabled');
            doGet('/useraccount/ClientAndTradingAccount');
            // Need Valid Test Data doPost('/useraccount/Save', {"PersonalEmailAddress":"not@realaddress.com","PersonalEmailAddressIsDirty":true})
            // Cfd Markets Test
            doGet('/cfd/markets?marketname=uk&maxresults=10&usemobileshortname=true');
            //Logoff
            doPost('/session/deleteSession?userName='+userName+'&session='+data.Session);
 
        });
        /* var userName = "<hidden>";
            cityindex.corsTesting.doPost('/session',{ "UserName": userName, "Password": "password"}, function (data, textCode) {
            });*/
        </textarea>
    <br />
    <button onclick="eval($('#code').val()); " style="background-color: #2C5E81;border: 1px;color: white;padding: 5px;">Execute</button>
    <button onclick="clearResults();" style="background-color: #2C5E81;border: 1px;color: white;padding: 5px;">Clear</button><br />
    <br/>Result<br />
    <select id="result" style="background-color: #e4e4e4; min-height: 300px; width: 100%; height:100%" multiple="multiple"></select>
    <hr />
</div>
        <script src="/TradingApi/Scripts/jquery-1.7.2.js"></script>
    </body>
</html>
Is this correct?  Where do I find the session token?

Share this post


Link to post

Hello,

From your post, it appears that you are using the Test Harness, which is getting rather old at this point in time. I would suggest you use the free (for individual users) API Development Environment known as "Postman" - https://www.getpostman.com/downloads/.

Using this tool you can POST your login credentials to the /session API endpoint and see the response from the server containing the Session token.

image.png

Kind Regards, PM

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×