I'm writing a wrapper for the Deutsche Bahn's Fahrplan OpenData API.
However, I cannot seem to produce the same result as a simple curl request as follows:
>>>import requests
>>>header = {'Authorization': 'Bearer 36e39957ace6f405a82cfb09522d0a8d'}
>>>departure_data = requests.get('https://api.deutschebahn.com/fahrplan-plus/v1/departureBoard/8011160?date=2017-06-30', headers=header)
# Now, using a journey's details id, lets request some journey details from the endpoint
>>>requests.get('https://api.deutschebahn.com/fahrplan-plus/v1/journeyDetails/' + departure_data.json()[0]['detailsId'], headers=header)
<Response [404]>
>>>requests.get('https://api.deutschebahn.com/fahrplan-plus/v1/journeyDetails/' + departure_data.json()[0]['detailsId'], headers=header).request.url
'https://api.deutschebahn.com/fahrplan-plus/v1/journeyDetails/782334%2F275830%2F795514%2F136979%2F80%3fstation_evaId%3D8098160'
Alright, so far, so bad. As you can see I'm using the data as given to me. Now, calling the endpoint via the Website, it tells me it runs this curl
command:
curl -X GET --header "Accept: application/json" --header "Authorization: Bearer 36e39957ace6f405a82cfb09522d0a8d" "https://api.deutschebahn.com/fahrplan-plus/v1/journeyDetails/782334%252F275830%252F795514%252F136979%252F80%253fstation_evaId%253D8098160"
And this bit of magic happens:
the original journey ID
'782334%2F275830%2F795514%2F136979%2F80%3fstation_evaId%3D8098160'
becomes:
'782334%252F275830%252F795514%252F136979%252F80%253fstation_evaId%253D8098160'
and returns a status 200
.
Out of seemingly nowhere, the journey id got some characters added to it. I copy & pasted it into the given field and nothing more, so I know it wasn't me.
I believe there is some sort of encoding/ decoding happening, but I've never seen this before, and honestly don't know what to make of it.
How do I handle this in my code? Clearly I need to do something in addition to simply parsing the departures
endpoint? Or, better yet, am I simply missing out on something obvious?
I've sent multiple mails to the DB developers, but so far have not heard from them back.