public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
263 stars 52 forks source link

PKP error - something changed? #285

Closed szoGGun closed 1 year ago

szoGGun commented 1 year ago

It looks like yesterday something has changed with pkp mgate endpoint.

New request for: Katowice                                                                                                                                                                                                               
[1] C:\Users\szoGGun\Desktop\pokolei.eu\src\frontend\node_modules\hafas-client\lib\request.js:150
[1]                             const err = new Error('invalid response content-type: ' + cType)
[1]                                         ^
[1]
[1] Error: invalid response content-type: text/html; charset=UTF-8
[1]     at C:\Users\szoGGun\Desktop\pokolei.eu\src\frontend\node_modules\hafas-client\lib\request.js:150:17
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[1]   response: Response {
[1]     size: 0,
[1]     timeout: 0,
[1]     [Symbol(Body internals)]: {
[1]       body: <ref *1> Gunzip {
[1]         _writeState: Uint32Array(2) [ 0, 0 ],
[1]         _readableState: ReadableState {
[1]           objectMode: false,
[1]           highWaterMark: 16384,
[1]           buffer: BufferList { head: null, tail: null, length: 0 },
[1]           length: 0,
[1]           pipes: [],
[1]           flowing: null,
[1]           ended: false,
[1]           endEmitted: false,
[1]           reading: false,
[1]           constructed: true,
[1]           sync: false,
[1]           needReadable: false,
[1]           emittedReadable: false,
[1]           readableListening: false,
[1]           resumeScheduled: false,
[1]           errorEmitted: false,
[1]           emitClose: true,
[1]           autoDestroy: true,
[1]           destroyed: false,
[1]           errored: null,
[1]           closed: false,
[1]           closeEmitted: false,
[1]           defaultEncoding: 'utf8',
[1]           awaitDrainWriters: null,
[1]           multiAwaitDrain: false,
[1]           readingMore: false,
[1]           dataEmitted: false,
[1]           decoder: null,
[1]           encoding: null,
[1]           [Symbol(kPaused)]: null
[1]         },
[1]         _events: [Object: null prototype] {
[1]           prefinish: [Function: prefinish],
[1]           unpipe: [Function: onunpipe],
[1]           error: [ [Function: onerror], [Function (anonymous)] ],
[1]           close: [Function: bound onceWrapper] {
[1]             listener: [Function: onclose]
[1]           },
[1]           finish: [Function: bound onceWrapper] {
[1]             listener: [Function: onfinish]
[1]           }
[1]         },
[1]         _eventsCount: 5,
[1]         _maxListeners: undefined,
[1]         _writableState: WritableState {
[1]           objectMode: false,
[1]           highWaterMark: 16384,
[1]           finalCalled: false,
[1]           needDrain: false,
[1]           ending: false,
[1]           ended: false,
[1]           finished: false,
[1]           destroyed: false,
[1]           decodeStrings: true,
[1]           defaultEncoding: 'utf8',
[1]           length: 7342,
[1]           writing: true,
[1]           corked: 0,
[1]           sync: false,
[1]           bufferProcessing: false,
[1]           onwrite: [Function: bound onwrite],
[1]           writecb: [Function: nop],
[1]           writelen: 7342,
[1]           afterWriteTickInfo: null,
[1]           buffered: [],
[1]           bufferedIndex: 0,
[1]           allBuffers: true,
[1]           allNoop: true,
[1]           pendingcb: 1,
[1]           constructed: true,
[1]           prefinished: false,
[1]           errorEmitted: false,
[1]           emitClose: true,
[1]           autoDestroy: true,
[1]           errored: null,
[1]           closed: false,
[1]           closeEmitted: false,
[1]           [Symbol(kOnFinished)]: []
[1]         },
[1]         allowHalfOpen: true,
[1]         bytesWritten: 0,
[1]         _handle: Zlib {
[1]           onerror: [Function: zlibOnError],
[1]           buffer: Buffer(7342) [Uint8Array] [
[1]              31, 139,   8,   0,   0,   0,   0,   0,   0,   3, 237, 189,
[1]             219, 114,  28,  71, 146,  40, 248,  12, 124,  69, 168, 116,
[1]              70,  85,  24,  86, 214,  21,  32,  64, 128, 128,  14,   8,
[1]              64,  20, 196,  11, 208,   0,  56,  28, 145, 205, 133,  69,
[1]             101,  70,  85,  37,  42,  43, 179, 148, 153, 133,  66, 149,
[1]              68, 179, 153, 222, 145, 237, 235, 174, 173, 237, 218,  81,
[1]             247, 185, 204, 195, 218,  49,  91, 219, 125, 107, 179,  53,
[1]              59, 231, 232, 169,  69, 188, 235,  27, 230,  75, 214,  61,
[1]              34,  50,  51, 242,
[1]             ... 7242 more items
[1]           ],
[1]           cb: [Function (anonymous)],
[1]           availOutBefore: 16384,
[1]           availInBefore: 7342,
[1]           inOff: 0,
[1]           flushFlag: 2,
[1]           [Symbol(owner_symbol)]: [Circular *1]
[1]         },
[1]         _outBuffer: Buffer(16384) [Uint8Array] [
[1]            60,  33,  68,  79,  67,  84,  89,  80,  69,  32, 104, 116,
[1]           109, 108,  62,  10,  60, 104, 116, 109, 108,  32, 108,  97,
[1]           110, 103,  61,  34, 112, 108,  34,  62,  10,  32,  32,  60,
[1]           104, 101,  97, 100,  62,  10,   9,  32,  32,  10,   9,  32,
[1]            32,   9,  32,  32,  10,   9,  32,  32,  60,  33,  45,  45,
[1]            32,  81, 117,  97, 110, 116,  99,  97, 115, 116,  32,  67,
[1]           104, 111, 105,  99, 101,  46,  32,  67, 111, 110, 115, 101,
[1]           110, 116,  32,  77,  97, 110,  97, 103, 101, 114,  32,  84,
[1]            97, 103,  32, 118,
[1]           ... 16284 more items
[1]         ],
[1]         _outOffset: 0,
[1]         _chunkSize: 16384,
[1]         _defaultFlushFlag: 2,
[1]         _finishFlushFlag: 2,
[1]         _defaultFullFlushFlag: 3,
[1]         _info: undefined,
[1]         _maxOutputLength: 4294967296,
[1]         _level: -1,
[1]         _strategy: 0,
[1]         [Symbol(kCapture)]: false,
[1]         [Symbol(kCallback)]: null,
[1]         [Symbol(kError)]: null
[1]       },
[1]           ],
[1]           'content-encoding': [ 'gzip' ],
[1]           'x-cache-status': [ 'MISS' ],
[1]           'x-frame-options': [ 'SAMEORIGIN' ],
[1]           'x-content-type-options': [ 'nosniff' ],
[1]           'x-xss-protection': [ '1; mode=block' ]
[1]         }
[1]       },
[1]       counter: 1
[1]     }
[1]   }
[1] }
derhuerst commented 1 year ago

It seems like the PKP endpoint works every once in a while. When I tried it from within the hafas-client repo with the following loop (fish shell), it worked in ~30% of the cases.

git clone https://github.com/public-transport/hafas-client.git
cd hafas-client
while true; ./tools/debug-cli/cli.js pkp locations 'katowice' | jq; sleep 10; end

Unfortunately, this is something that we can't do anything about, except complain maybe that their app is broken because of this. (Don't complain that you can't access their HAFAS API, as it is unofficial and intended for the mobile app.)

derhuerst commented 1 year ago

I'm going to close this Issue because we don't have control over their endpoint. If you have more questions about this, or news about the status of their API, please respond and/or re-open the Issue.

derhuerst commented 1 year ago

related: https://github.com/public-transport/hafas-client/issues/184

volo-droid commented 1 year ago

@derhuerst access to both sitkol.pl and rozklad-pkp.pl is restricted from abroad (they also restrict connection from the Polish VPN servers I was able to try). AFAICS the hosts can be accessed only from Poland and Ukraine (which is really nice of them).

derhuerst commented 1 year ago

In this case, if you have the ability to do it legally (I'm referring to the discussion in https://github.com/public-transport/hafas-client/issues/184), can you check if the hafas-client PKP integration still works?

volo-droid commented 1 year ago

@derhuerst Nope, the integration doesn't work. The endpoint now expects a MAC as a query parameter which is computed by the app, and verified by the server. Taking into account this and the mentioned discussion one can safely assume the owners of the endpoint really want to prevent public access to it.