"401 - Unauthorized" when trying to access LDBWS

309 views
Skip to first unread message

Simon Burgess

unread,
Mar 19, 2018, 9:19:47 AM3/19/18
to A gathering place for the Open Rail Data community
Hi,

I registered for LDBWS access almost exactly a month ago but I've only just got around to trying to use it today.

I'm using some simple Python with Zeep but keep getting 401s back.  Is it likely that my token has expired because I registered and then didn't use it for a month? Or am I just doing something wrong with the token?

My code (Python 3.4) looks like this:

from zeep import Client


client = Client('https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2017-10-01')


token_type = client.get_type('ns0:AccessToken')

token = token_type(TokenValue=‘my-token-goes-here’)


result = client.service.GetDepartureBoard(3, "NSG", "MOG", None, None, None,

                                               _soapheaders=[token])


The request is sent to https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx as this (HTTP Post):

<?xml version='1.0' encoding='utf-8'?>

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header><ns0:TokenValue xmlns:ns0="http://thalesgroup.com/RTTI/2013-11-28/Token/types">my-token-goes-here</ns0:TokenValue></soap-env:Header><soap-env:Body><ns0:GetDepartureBoardRequest xmlns:ns0="http://thalesgroup.com/RTTI/2017-10-01/ldb/"><ns0:numRows>3</ns0:numRows><ns0:crs>NSG</ns0:crs><ns0:filterCrs>MOG</ns0:filterCrs></ns0:GetDepartureBoardRequest></soap-env:Body></soap-env:Envelope>


Is there something silly I'm missing?

Thanks,
-Simon.

Simon Burgess

unread,
Mar 20, 2018, 7:31:20 AM3/20/18
to A gathering place for the Open Rail Data community
For anyone interested, the fix for this was to construct the SOAP header differently in Zeep.

The problem was that, in the original generated SOAP header, the TokenValue wasn't wrapped in an AccessToken tag

Doing this:

token_construct = xsd.Element(

    '{http://thalesgroup.com/RTTI/2013-11-28/Token/types}AccessToken',

    xsd.ComplexType([

        xsd.Element(

            '{http://thalesgroup.com/RTTI/2013-11-28/Token/types}TokenValue',

            xsd.String()),

    ])

)

token = token_construct(TokenValue='my-token-goes-here')


Meant that the SOAP header included this:

<ns0:AccessToken xmlns:ns0="http://thalesgroup.com/RTTI/2013-11-28/Token/types"><ns0:TokenValue>my-token-goes-here</ns0:TokenValue></ns0:AccessToken>


And now everything is working.

Maybe this is quite Python/Zeep specific, but thought this might help others who follow!

-Simon.
Reply all
Reply to author
Forward
0 new messages