Open pc-coholic opened 5 years ago
Note for people stumbling over this via Google:
The endpoint seems to check the user agent and restricts access for eg. using request's default one. The following works for me as of today:
station = 2 # Marienplatz
url = f'https://www.mvg.de/fahrinfo/api/departure/{station}?footway=0'
headers = {'X-MVG-Authorization-Key': '5af1beca494712ed38d313714d4caff6', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'}
requests.get(url, headers=headers).json()
Hi,
i try to use your sample but did not work... do you have any idea why, is there any change in the MVG API?
Br, RObert
That is quite possible - they love to change things around...
A quick check on their website reveals, that there have apparently been some changes...
For example, the call for Marienplatz is now https://www.mvg.de/api/fahrinfo/departure/de:09162:2?footway=0
, the one for Ostbahnhof https://www.mvg.de/api/fahrinfo/departure/de:09162:5?footway=0
.
The Search-Endpoint (https://www.mvg.de/api/fahrinfo/location/queryWeb?q=ost
) will provide you with the correct station id.
Furthermore, the API-token seems to be now x-api-token: Vv7L4Gbu2k
.
Someone[TM] should really update this library to use the new endpoints and data ;-)
Thanks, i did nearly the same and check with chrome developer tools and now your code works with the new station ID´s :-) THanks!
The api token was not required in my case
MVG has launched a new API while keeping the old one online.
Unfortunately, it seems like the data served by the old (currently used) API is staring to degrade. For example, queries for Garching-Hochbrück only return U-Bahn-trains but not any busses.
The new API lives at
https://www.mvg.de/fahrinfo/api/departure/480?footway=0
, wherefootway
takes the currenttimeoffset
parameter and480
is the ID of the station (in this example: Garching-Hochbrück).Querying for station-data can be done at
https://www.mvg.de/fahrinfo/api/location/queryWeb?q=garching
, with theq
-parameter obviously being the search-string.Queries need to be authorized by providing the
"X-MVG-Authorization-Key
-header. One possible value is for example5af1beca494712ed38d313714d4caff6
(mvg.de website-key).The new API is a lot more usable as it does not need any of that RPC-decryption that is currently used.
If anyone feels like implementing the new API - possibly while keeping compatibility to the current Syntax: please do so :-)