You are reading a single comment by @yoshy and its replies. Click here to read the full conversation.
  • Looking at learning about API query via Python.

    Using live bus data from data.bus-dft.gov.uk that says it ouputs in json. https://data.bus-data.dft.gov.uk/guidance/requirements/?section=api

    I get status code 200 and can view the data via both url in browser or via print(response.text) but as soon as I try any of the entry level json lines in the script it fails:

    Script example:

    import requests
    url = 'https://data.bus-data.dft.gov.uk/api/v1/datafeed/1695/?api_key=***'
    response = requests.get(url)
    print("Status code:", response.status_code)
    try:
        print(response.json())
    except ValueError:  # includes simplejson.decoder.JSONDecodeError
        print('Decoding JSON has failed')
    

    Error without the try/except bit, I.e. just keeping print(response.json())

    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    

    I can't find a relatable solution to this anywhere other than suggestions the results aren't JSON?

    Has anyone here messed around with dft data and found it behaves like this?

    All the online docs suggest this is a really simple concept but as always I quickly run out of ideas when it comes to trying to learn in practice. Feels like it should be a 1 minute "oh yeah thats cool" early learning step surely?

  • Have you got a screenshot of the raw data in browser? Does sound like there's something up with the data itself

About

Avatar for yoshy @yoshy started