Problem with my code or the feed

311 views
Skip to first unread message

Félix Desjardins

unread,
Nov 2, 2018, 3:33:19 PM11/2/18
to GTFS-realtime
Hi,

I am new with the GTFS-realtime world as my local transit system (STM - Société de transport de Montréal) just opened their feed yesterday!

I have some problem with my program and I'm not sure if the problem is from my code or the feed.

Here is a link to their website : https://developpeurs.stm.info/ (you need a header apiKey to access the feed)

Here is a link to a snapshot of the feed : https://github.com/FelixINX/gtfs-rt-stm/blob/master/gtfsrt.pb

And here is my code :
var GtfsRealtimeBindings = require('gtfs-realtime-bindings');
var request = require('request');

var requestSettings = {
  method: 'POST',
  encoding: null,
  headers: {
    'apikey': 'MYAPIKEY'
  }
};
request(requestSettings, function (error, response, body) {
  if (!error) {
    var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
    console.log(feed);
    feed.entity.forEach(function(entity) {
      if (entity.trip_update) {
        console.log(entity.trip_update);
      }
    });
  }
});

When I run the code I get the following error :

/mnt/b/Users/Félix/Documents/Atelier web/stm-gtfs-realtime/node_modules/protobufjs/ProtoBuf.js:1987
                            throw(e);
                            ^

Error: Missing at least one required field for Message .transit_realtime.FeedMessage: header
    at ...

I also run the GTFS-realtime validator and got the following error :
  • E003 GTFS-rt trip_id does not exist in GTFS data and does not have schedule_relationship of ADDED
  • E004 GTFS-rt route_id does not exist in GTFS data
  • E039 FULL_DATASET feeds should not include entity.is_deleted
  • W009 schedule_relationship not populated
The goal of my project is to convert the feed into JSON to use it in a web application. If you know a quick and easy way to do this, please let me know!

Thanks :-)


Sean Barbeau

unread,
Nov 5, 2018, 9:29:45 AM11/5/18
to GTFS-realtime
Felix,
From the error it sounds like the protobuf data you're trying to parse doesn't have a required field in the header of the GTFS-rt feed.

However, if the gtfs-realtime-validator parses the feed correctly but your code doesn't, it probably means that you aren't passing the right information into GtfsRealtimeBindings.FeedMessage.decode(body).

Have you tried looking at the body via debugger or browser to confirm that it is indeed the protobuf?

When working on the validator I recall some feeds having redirects or other configurations that required a bit of extra code to handle these cases.

Sean
Reply all
Reply to author
Forward
0 new messages