简体   繁体   English

api上的请求无效(Curl和python)

[英]Requests on a api doesn't work (Curl and python)

So, I try to make a program who tell me the schedule of my bus, i take this real time information on an Api: 因此,我尝试制作一个程序来告诉我公交车的时间表,并在Api上获取以下实时信息:

https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100385%3A385&stop_point_id=StopPoint%3A59%3A6195786 https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100385%3A385&stop_point_id=StopPoint%3A59%3A6195786

but when i lunch it there is an error : 但是当我午餐时有一个错误:

"error": "Unknown dataset: tr-vianavigo"

I have a token to use I think but how ? 我想使用令牌,但是怎么用? the Curl for this api is : 该api的Curl为:

curl -X GET --header "Accept: application/json" "https://api-lab-trone- 
stif.opendata.stif.info/service/tr-vianavigo/departures? 
line_id=100100020%3A20&stop_point_id=59%3A4726914"

when i use the first url on my web browser it work and show me : 当我在网络浏览器上使用第一个网址时,它可以工作并显示给我:

[
  {
    "lineDirection": "Juvisy RER",
    "code": "duration",
    "time": "12"
  },
  {
    "lineDirection": "Savigny Toulouse-Lautrec",
    "code": "duration",
    "time": "20"
  },
  {
    "lineDirection": "Juvisy RER",
    "code": "duration",
    "time": "38"
  },
  {
    "lineDirection": "Savigny Toulouse-Lautrec",
    "code": "duration",
    "time": "45"
  }
]

but in python if i just test : 但是如果我只是在python中测试:

import requests 

#my token
apikey = 'ef169369dfd911b01371b73e975ed88adce881bc92dbbd9720551c94'

#url of the api
url ='https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100385%3A385&stop_point_id=StopPoint%3A59%3A6195786'

#requests
r = requests.get(url, apikey)

print(r.text)

it make the error : 它使错误:

    "error": "Unknown dataset: tr-vianavigo"

You must use one of your API keys for this purpose. 为此,您必须使用您的API密钥之一。 An API key is obtained via your user account in My API keys . 通过“ 我的API密钥”中的用户帐户可以获取API密钥 Once generated, the key must be inserted as a query parameter ( apikey ) in the URL of your call. 密钥生成后,必须作为查询参数( apikey )插入到您的调用URL中。 For your example: 例如:

curl -X GET --header "Accept: application/json" "https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100020%3A20&stop_point_id=59%3A4726914&apikey=<YOUR-API-KEY>"

FYI, the scope of the real-time data available on the dataset tr-unitaire-stif is avalaible here . 仅供参考, 此处可获取数据集tr-unitaire-stif上的实时数据范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM