Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All requests are crashing #11

Closed
baptistesola2 opened this issue Nov 24, 2019 · 13 comments
Closed

All requests are crashing #11

baptistesola2 opened this issue Nov 24, 2019 · 13 comments

Comments

@baptistesola2
Copy link

  • trainline version: 0.1.0
  • Python version: 3.7
  • Operating System: macOS

Description

All requests return the same error:
requests.exceptions.ConnectionError: Status code 400 for url https://www.trainline.eu/api/v5_1/search
{"error":{"code":"no_results","message":{}}}

What I Did

It used to work very well, but for the last few days, no requests I've tried have seem to work.
I tried to use both the trainline_cli.py file and the Docker Image (downloaded today November 24th)

trainline --departure="Toulouse" --arrival="Nantes" --next=12hours
trainline --departure="Bordeaux" --arrival="Lille" --next=12hours

Complete Traceback :
Traceback (most recent call last):
  File "/app/bin/trainline_cli.py", line 104, in <module>
    main()
  File "/app/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/app/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/app/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/app/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/app/bin/trainline_cli.py", line 75, in main
    transportation_mean=transport)
  File "/app/trainline/__init__.py", line 606, in search
    passenger_list=passenger_list)
  File "/app/trainline/__init__.py", line 129, in search
    ret = c._post(url=_SEARCH_URL, post_data=post_data)
  File "/app/trainline/__init__.py", line 83, in _post
    status=ret.status_code, url=url, content=ret.text))
requests.exceptions.ConnectionError: Status code 400 for url https://www.trainline.eu/api/v5_1/search
{"error":{"code":"no_results","message":{}}}
@tducret
Copy link
Owner

tducret commented Nov 24, 2019

Same here. It seems that the version of the user agent is checked, and the one embedded in this Python package is too old.
Updating it to CaptainTrain/1574360965(web) (Ember 3.5.1) fixes the problem.
I'm going to release it in the next minutes.
Thanks @baptistesola2

tducret added a commit that referenced this issue Nov 24, 2019
Change user-agent to avoid error 400 (issue #11)
@tducret
Copy link
Owner

tducret commented Nov 24, 2019

@baptistesola2 I think it's okay now. Could you please upgrade to v0.1.1 and test it?
Python package : pip install -U trainline
Docker image: trainline --upgrade

trainline --departure="Toulouse" --arrival="Nantes" --next=12hours

departure_date;arrival_date;duration;number_of_segments;price;currency;transportation_mean;bicycle_reservation
24/11/2019 16:45;24/11/2019 23:51;07h06;2;280,1;EUR;train;unavailable
24/11/2019 16:45;24/11/2019 23:51;07h06;2;217,1;EUR;train;unavailable
24/11/2019 16:45;24/11/2019 23:51;07h06;2;219,9;EUR;train;unavailable
24/11/2019 22:30;25/11/2019 09:52;11h22;2;210,0;EUR;train;unavailable
24/11/2019 22:30;25/11/2019 09:52;11h22;2;176,8;EUR;train;20,0

Waiting for you reply to close the issue.

@antoinevth
Copy link
Contributor

I still have the error 400 using pip module.

@py29
Copy link

py29 commented Nov 24, 2019

Hi
I have the same issue. Still 400

@baptistesola2
Copy link
Author

Hi @tducret . Yes both the package and the docker image are working for me now !
Thanks so much for your amazing reactivity !

@tducret
Copy link
Owner

tducret commented Nov 25, 2019

@py29 and @antoinevth Could you make sure that you have version 0.1.1of the module?
pip freeze | grep trainline

@antoinevth
Copy link
Contributor

Yes I did the update : pip3 freeze | grep trainline returns trainline==0.1.1
And python3 trainline_cli.py --departure="Paris" --arrival="Nantes" --next=12hours returns :

Traceback (most recent call last):
  File "trainline_cli.py", line 104, in <module>
    main()
  File "/root/.local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/root/.local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/root/.local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/.local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "trainline_cli.py", line 75, in main
    transportation_mean=transport)
  File "/root/.local/lib/python3.7/site-packages/trainline/__init__.py", line 606, in search
    passenger_list=passenger_list)
  File "/root/.local/lib/python3.7/site-packages/trainline/__init__.py", line 129, in search
    ret = c._post(url=_SEARCH_URL, post_data=post_data)
  File "/root/.local/lib/python3.7/site-packages/trainline/__init__.py", line 83, in _post
    status=ret.status_code, url=url, content=ret.text))
requests.exceptions.ConnectionError: Status code 400 for url https://www.trainline.eu/api/v5_1/search
{"error":{"code":"no_results","message":{}}}

@yann120
Copy link

yann120 commented Nov 26, 2019

Hi,
I have the same problem since two days.
I heard on the TGVMAX Facebook group that Trainline is changing his mobile App.
Maybe they are changing their API also ?
Every request that I try with Postman on https://www.trainline.eu/api/v5_1/search ended with a 400 error...

@benoitdemaegdt
Copy link

Hi,
I also call Trainline API to detect available TGVmax travels.
Few days ago, my API calls got rejected. Changing the user agent to CaptainTrain/1574360965(web) (Ember 3.5.1) as mentioned by @tducret solved the issue.

But since the 27/11/2019, my API calls are once again being rejected.
The reason :

{"errors":{"passengers":["Veuillez creer un compte pour reserver vos voyages TGVMax"]}}

As you said @yann120 , Trainline changed their API. I'll try to dig this issue later, I'll come back here if I find something helpful 😄

@benoitdemaegdt
Copy link

Hi,
As I said yesterday, Trainline changed it's API and you now need an account if you want to book a TGVmax ticket.

IMG_8234

Here is a quick recap of the changes :
OLD API

headers = {
    'Accept': 'application/json',
    'User-Agent': 'CaptainTrain/5221(d109181b0) (iPhone8,4; iOS 13.1.2; Scale/2.00)',
    'Accept-Language': 'fr',
    'Content-Type': 'application/json; charset=UTF-8',
    'Host': 'www.trainline.eu',
}

body = {
    "local_currency": "EUR",
    "search": {
      "passengers": [
        {
          age: 25,
          id: 'ccddfbfd-d7f5-43bf-8b64-bd92aaaf116e', # random id
          label: 'abe09e23-2d9e-4a4b-a9e3-3318e1caaf6b', # random label
          cards: [{
            reference: 'SNCF.HappyCard',
            number: '<YOUR_TGVMAX_NUMBER>'
          }],
        }
      ],
      "departure_station_id":<DEPARTURE_STATION_ID>,
      "arrival_station_id":<ARRIVAL_STATION_ID>,
      "departure_date": <DATE>,
      "systems": [
          "sncf",
      ]
    }
}

NEW API

headers = {
    'Accept': 'application/json',
    'User-Agent': 'CaptainTrain/5221(d109181b0) (iPhone8,4; iOS 13.1.2; Scale/2.00)',
    'Accept-Language': 'fr',
    'Content-Type': 'application/json; charset=UTF-8',
    'Host': 'www.trainline.eu',
    'authorization': 'Token token="<YOUR_TOKEN>"',
}

body = {
    "local_currency": "EUR",
    "search": {
      "passenger_ids": [
        "<YOUR_PASSENGER_ID>"
      ],
      "card_ids": [
        "<YOUR_CARD_ID>"
      ],
      "departure_station_id":<DEPARTURE_STATION_ID>,
      "arrival_station_id":<ARRIVAL_STATION_ID>,
      "departure_date": <DATE>,
      "systems": [
          "sncf",
      ]
    }
}

3 things changed :

  • you need an authorization header
  • you need a passenger id in the request body
  • you need a card id in the request body

I hope it can help ...

@clairbaptiste
Copy link

how can we get authorization header ?

@antoinevth
Copy link
Contributor

antoinevth commented Oct 15, 2020

I just tried again today. I don't have the 400 error any more.
Regarding TGVmax, I think it's not linked to the original issue.
Maybe we should close this one and open another one to find solutions for TGVmax?

@antoinevth
Copy link
Contributor

This issue is solved. It should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants