public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
277 stars 53 forks source link

SBB endpoint fails with CGI_READ_FAILED #229

Closed derhuerst closed 3 years ago

derhuerst commented 3 years ago

from https://github.com/public-transport/hafas-client/issues/228#issuecomment-817372799:

The sbb profil works fine with the station 'Zürich Kreuzplatz' (ID: 8530813). The problem occurs with the Station 'Thalwil' (ID: 8503202).

When I'm asking for departures in the next minute I get a valid answer.

Code snipped:

const thalwil = '8503202' // Thalwil
client.departures(thalwil, {duration: 1})
...

Response:

[
  {
    tripId: '1|115564|15|85|11042021',
    stop: {
      type: 'stop',
      id: '8573167',
      name: 'Thalwil, Zentrum',
      location: {
        type: 'location',
        id: '8573167',
        latitude: 47.294919,
        longitude: 8.564464
      },
      products: {
        'express-train': false,
        'international-train': false,
        'interregional-train': true,
        'regional-express-train': true,
        watercraft: true,
        'suburban-train': true,
        'bus-taxi': true,
        gondola: false,
        'car-train': false,
        tram: false
      }
    },
    when: '2021-04-11T22:49:00+02:00',
    plannedWhen: '2021-04-11T22:49:00+02:00',
    delay: null,
    platform: null,
    plannedPlatform: null,
    direction: 'Thalwil, Böni',
    provenance: null,
    line: {
      type: 'line',
      id: 'h-142-000807',
      fahrtNr: '20153',
      name: 'B 142',
      public: true,
      adminCode: '000807',
      mode: 'bus',
      product: 'bus-taxi',
      operator: {
        type: 'operator',
        id: 'automobildienst-szu',
        name: 'Automobildienst SZU'
      }
    },
    remarks: [
      { type: 'hint', code: '1', text: 'B 142' },
      { type: 'hint', code: '2', text: 'Bus 142 20153' },
      { type: 'hint', code: '3', text: 'B 142 20153' },
      { type: 'hint', code: '4', text: 'B 142 20153' },
      { type: 'hint', code: '1', text: 'B 142' },
      { type: 'hint', code: '2', text: 'Bus 142 20153' },
      { type: 'hint', code: '3', text: 'B 142 20153' },
      { type: 'hint', code: '4', text: 'B 142 20153' },
      { type: 'hint', code: 'NF', text: 'Niederflureinstieg' },
      {
        type: 'hint',
        code: 'OM',
        text: 'Maskenpflicht für Reisende ab 12 Jahren'
      },
      { type: 'hint', code: 'FD', text: '20153' }
    ]
  }
]

But when I'm asking for departures in the next 10 minutes I get an error.

Code snipped:

const thalwil = '8503202' // Thalwil
client.departures(thalwil, {duration: 10})
...

Response:

Error: CGI_READ_FAILED
    at Object.request (/.../hafas-client/lib/request.js:108:14)
    at _stationBoard (/.../hafas-client/index.js:76:18)
    at Object.departures (/.../hafas-client/index.js:87:10)
    at Object.<anonymous> (/.../hafas-client/p/sbb/example.js:11:8)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  isHafasError: true,
  request: '{"lang":"deu","svcReqL":[{"meth":"StationBoard","req":{"type":"DEP","date":"20210411","time":"224817","stbLoc":{"type":"S","lid":"A=1@L=8503202@"},"dirLoc":null,"jnyFltrL":[{"type":"PROD","mode":"INC","value":"1023"}],"dur":10,"getPasslist":false,"stbFltrEquiv":false}}],"client":{"type":"AND","id":"DBZUGRADARNETZ","v":""},"ver":"1.18","auth":{"aid":"hf7mcf9bv3nv8g5f","type":"AID"}}',
  url: 'http://fahrplan.sbb.ch/bin/mgate.exe?',
  statusCode: 200,
  code: 'CGI_READ_FAILED',
  responseId: null
}
derhuerst commented 3 years ago

When I'm asking for departures in the next minute I get a valid answer. Code snipped:

const thalwil = '8503202' // Thalwil
client.departures(thalwil, {duration: 1})
...

But when I'm asking for departures in the next 10 minutes I get an error. Code snipped:

const thalwil = '8503202' // Thalwil
client.departures(thalwil, {duration: 10})
...

Currently, I cannot confirm that. I use the debug-cli helper, but it basically does the same:

./tools/debug-cli/cli.js sbb departures 8503202 | jq
# works, I get departures
./tools/debug-cli/cli.js sbb departures 8503202 '{duration: 10}' | jq
# works too

Possible causes:

You can help me debug this by running your tests with the DEBUG=hafas-client environment variable. This way, I can see all raw requests and responses.

vkrause commented 3 years ago

Managed to reproduce with KPublicTransport, not for Thalwil (8503202) though, but Basel SBB (8500010).

Request: {"auth":{"aid":"hf7mcf9bv3nv8g5f","type":"AID"},"client":{"id":"DBZUGRADARNETZ","type":"AND"},"formatted":false,"lang":"de","svcReqL":[{"meth":"ServerInfo","req":{"getServerDateTime":true,"getTimeTablePeriod":false}},{"cfg":{"polyEnc":"GPA"},"meth":"StationBoard","req":{"date":"20210413","maxJny":20,"stbFltrEquiv":true,"stbLoc":{"extId":"8500010","type":"S"},"time":"165204","type":"DEP"}}],"ver":"1.18"}

Response: {"ver":"1.18","lang":"deu","id":"dq26xkxmga449i8x","err":"OK","svcResL":[{"meth":"ServerInfo","err":"OK","res":{"common":{"locL":[],"prodL":[],"polyL":[],"layerL":[{"id":"standard","name":"standard","index":0,"annoCnt":0}],"crdSysL":[{"id":"standard","index":0,"type":"WGS84"}],"opL":[],"remL":[],"icoL":[]},"sD":"20210413","sT":"165204","enc":"ISO-8859-1","planrtTS":"1618325456"}},{"meth":"StationBoard","err":"CGI_READ_FAILED"}]}

Further observations:

KristjanESPERANTO commented 3 years ago

Okay, with 10 minutes it works now for me also. But with 20 minutes not.

You can help me debug this by running your tests with the DEBUG=hafas-client environment variable. This way, I can see all raw requests and responses.

I have no experience with enviroment variables in node. I found something with duckduckgo and tried this, but I don't get a helpful result. How do I do that?

derhuerst commented 3 years ago

You can help me debug this by running your tests with the DEBUG=hafas-client environment variable. [...]

I have no experience with environment variables in node. [...]

Environment variables are a shell/OS thing, rather than a Node-specific thing.

On Unix-like operating systems (macOS, Linux) and if you're using bash (the default shell on almost all Unix-like OSes), you would just add DEBUG=hafas-client in front of your command, e.g. DEBUG=hafas-client node my-hafas-client-test-script.js.

On Windows, I think it depends on the shell (PowerShell vs cmd.exe vs something else) you're using.

KristjanESPERANTO commented 3 years ago

Oh, okay. Thank you :slightly_smiling_face: Here is my request command (under Debian) and the result:

$ DEBUG=hafas-client node ./tools/debug-cli/cli.js sbb departures 8503202 '{duration: 20}' | jq

{"lang":"deu","svcReqL":[{"meth":"StationBoard","req":{"type":"DEP","date":"20210414","time":"181703","stbLoc":{"type":"S","lid":"A=1@L=8503202@"},"dirLoc":null,"jnyFltrL":[{"type":"PROD","mode":"INC","value":"1023"}],"dur":20,"getPasslist":false,"stbFltrEquiv":false}}],"client":{"type":"AND","id":"DBZUGRADARNETZ","v":""},"ver":"1.18","auth":{"aid":"hf7mcf9bv3nv8g5f","type":"AID"}}
{"ver":"1.18","lang":"deu","id":"","err":"OK","svcResL":[{"meth":"StationBoard","err":"CGI_READ_FAILED"}]}
Error: CGI_READ_FAILED
    at Object.request (/.../hafas-client/lib/request.js:108:14)
    at _stationBoard (/.../sbb-problem/hafas-client/index.js:76:18)
    at departures (/.../sbb-problem/hafas-client/index.js:87:10)
    at Object.<anonymous> (/.../sbb-problem/hafas-client/tools/debug-cli/cli.js:61:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  isHafasError: true,
  request: '{"lang":"deu","svcReqL":[{"meth":"StationBoard","req":{"type":"DEP","date":"20210414","time":"181703","stbLoc":{"type":"S","lid":"A=1@L=8503202@"},"dirLoc":null,"jnyFltrL":[{"type":"PROD","mode":"INC","value":"1023"}],"dur":20,"getPasslist":false,"stbFltrEquiv":false}}],"client":{"type":"AND","id":"DBZUGRADARNETZ","v":""},"ver":"1.18","auth":{"aid":"hf7mcf9bv3nv8g5f","type":"AID"}}',
  url: 'http://fahrplan.sbb.ch/bin/mgate.exe?',
  statusCode: 200,
  code: 'CGI_READ_FAILED',
  responseId: null
}

Is that helpful?

derhuerst commented 3 years ago

Is that helpful?

Yes and no. 😄 It didn't help me figure out in which specific case the SBB endpoint returns CGI_READ_FAILED, but as requested it documents another request that causes it. 👍

derhuerst commented 3 years ago

Closing since the SBB seems to be shut off (#245).