Skip to content

KeyError: 'x-security-token' #1

@femtotrader

Description

@femtotrader

Hello,

I'm trying for the first time you Python IG Market API code with a demo account but it raises

{"accountType":"CFD","accountInfo":{"balance":30000.0,"deposit":0.0,"profitLoss":0.0,"available":30000.0},"currencyIsoCode":"EUR","currencySymbol":"E","currentAccountId":"HIDDEN_DATA","lightstreamerEndpoint":"https://demo-apd.marketdatasystems.com","accounts":[{"accountId":"HIDDEN_DATA","accountName":"Demo-CFD","preferred":true,"accountType":"CFD"}],"clientId":"HIDDEN_DATA","timezoneOffset":1,"hasActiveDemoAccounts":true,"hasActiveLiveAccounts":true,"trailingStopsEnabled":false,"reroutingEnvironment":null,"dealingEnabled":true}
Traceback (most recent call last):
  File "main.py", line 10, in <module>
    account_info = ig_service.switch_account('HIDDEN_DATA', False)
  File "/Users/femto/fx/femtoprojects/python/ig_markets/ig-markets-rest-api-python-library/ig_service.py", line 371, in switch_account
    self.set_headers(response.headers, False)
  File "/Users/femto/fx/femtoprojects/python/ig_markets/ig-markets-rest-api-python-library/ig_service.py", line 421, in set_headers
    self.SECURITY_TOKEN = response_headers['X-SECURITY-TOKEN']
  File "/Users/femto/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/requests/structures.py", line 54, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'x-security-token'

I did this

    try:
        self.SECURITY_TOKEN = response_headers['X-SECURITY-TOKEN']
    except:
        self.SECURITY_TOKEN = None

to fix it

But I don't know if that's risky.

Kind regards

Femto

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions