tgvmax-bot icon indicating copy to clipboard operation
tgvmax-bot copied to clipboard

Log error and backend down using Trainline Checker

Open Grodzeus opened this issue 2 years ago • 15 comments

Hi there,

I've been experiencing an error since 2 days ago that forces my backend container to restart every minute. Would you know what is it about? Here is the recurring (30+ times) errir I get on my logs before every restart:

` 2 travel(s) initiated. 0 cron(s) initiated. App listen on 0.0.0.0:8080

/usr/src/src/book/trainline.ts:298 this.token.passengers = token.passengers.filter(p => p.is_selected) ^ TypeError: Cannot read properties of undefined (reading 'filter') at TrainlineAuthentifier.login (/usr/src/src/book/trainline.ts:298:46) at processTicksAndRejections (node:internal/process/task_queues:96:5) at TrainlineAuthentifier.getToken (/usr/src/src/book/trainline.ts:262:7) at TrainlineSearcherAndBooker.search (/usr/src/src/book/trainline.ts:654:22) at Object.next (/usr/src/src/book/trainline.ts:552:21) at TrainlineSearcherAndBooker.list (/usr/src/src/book/trainline.ts:490:41) at TrainlineSearcherAndBooker.check (/usr/src/src/book/trainline.ts:735:19) `

Thank you for your tool and time !

Grodzeus avatar Oct 18 '22 23:10 Grodzeus

Try to connect to your Trainline business account to ensure your credentials are still valid

Eywek avatar Oct 19 '22 07:10 Eywek

Trainline acocunt still running and website research with it shows me TGVmax places

Grodzeus avatar Oct 19 '22 12:10 Grodzeus

UPDATE: Getting a captcha check from the signin endpoint Token in JSON format looks like this: {"url":"https://geo.captcha-delivery.com/captcha/?initialCid=XXX&cid=XXX&referer=HTTPS%3A%2F%2Fwww.trainline.fr%2Fapi%2Fv5_1%2Faccount%2Fsignin&hash=XXX&t=fe&s=XXXXX&e=XXXXX"}

Grodzeus avatar Oct 22 '22 18:10 Grodzeus

The current code use those hardcoded creds: https://github.com/Eywek/tgvmax-bot/blob/master/backend/src/book/trainline.ts#L22, they might just have changed them

vmarchaud avatar Oct 22 '22 19:10 vmarchaud

Same issue here !

Also, we should improve the behaviour when something like that happens, because the backend is now restarting a lot, and the frontend doesn't display any information (it looks like you lost all your data)

TBG-FR avatar Nov 28 '22 12:11 TBG-FR

Same issue here too. Is there a fix available or not yet ?

MrVidipy avatar Feb 08 '23 08:02 MrVidipy

A PR has been opened (https://github.com/Eywek/tgvmax-bot/pull/29) but wasn't finished so feel free to make another one

vmarchaud avatar Feb 08 '23 09:02 vmarchaud

A PR has been opened (#29) but wasn't finished so feel free to make another one

That PR isn't about the issue we're facing here. Either the API changed, or the credentials. Someone needs to investigate, see what Trainline web or mobile app is using/sending, and make a PR 😅

TBG-FR avatar Feb 08 '23 17:02 TBG-FR

So I tried to dig a little into that problem, and I think the problem is that they have an anti-bot system.

Like @Grodzeus said :

UPDATE: Getting a captcha check from the signin endpoint

When I use the website I'm often asked to complete the captcha to proceed. However, the but can't complete it thus returning a null request. I don't know if any of you have a workaround but, if not, does this means the bot is dead?

MrVidipy avatar Feb 15 '23 18:02 MrVidipy

I don't know if any of you have a workaround but, if not, does this means the bot is dead?

You should try to replicate how HTTP requests are done by the Trainline business application

Eywek avatar Feb 15 '23 19:02 Eywek

I already compared the requests between the bot and the app and I don't think the requests are the problem here.

However, we still have the same issue :

Screenshot_20230215_202934_TrainlineforBusiness.jpg

Even in the Business app, we're asked to complete the captcha.

MrVidipy avatar Feb 15 '23 19:02 MrVidipy

Thanks for the investigation @MrVidipy !

btw, I tried months ago to send them a mail to get a legal access to the api, after seeing https://www.thetrainline.com/solutions/api and they never answered...

However, we could maybe send this captcha to the frontend then, with a little bit of code modifications 🤔

TBG-FR avatar Feb 15 '23 19:02 TBG-FR

btw, I tried months ago to send them a mail to get a legal access to the api, after seeing https://www.thetrainline.com/solutions/api and they never answered...

I just send a mail to ask about their pricing. We'll see if they respond.

However, we could maybe send this captcha to the frontend then, with a little bit of code modifications 🤔

Yeah, why not but it defies the goal of the bot if the captcha is required during the night. And from what I saw, Trainline is asking for the captcha very often (like every few requests).

MrVidipy avatar Feb 15 '23 20:02 MrVidipy

I just send a mail to ask about their pricing. We'll see if they respond.

I hope you'll have better luck than me

Yeah, why not but it defies the goal of the bot if the captcha is required during the night. And from what I saw, Trainline is asking for the captcha very often (like every few requests).

You're right, sadly it won't work well... And I'm not sure we're eager to go down the path of captcha solvers

TBG-FR avatar Feb 15 '23 22:02 TBG-FR

the initial issue is fixed by https://github.com/Eywek/tgvmax-bot/commit/0e7dcd2accff9e583b90bdd6ac8197c09cd9f33a

But Trainline is still trying to block us with a captcha, personally I don't use "travels" anymore and I only use the bot UI to search for available TGVMax

Eywek avatar Jul 06 '23 14:07 Eywek