0

I'm having a very strange problem.

This code, which was working perfectly yesterday, is now throwing the error -

File "/usr/local/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here is the code.

    # Request documentation at - https://chargepoints.dft.gov.uk/api/help
    @app.route("/chargepoints", methods=["GET", "POST"])
    def charge():
        if request.method == "POST":
    
           # retrieve variables from session
            latitude = session['latitude']
            longitude = session['longitude']
            distance = request.form.get("distance")
            #postcode = session['postcode']

            # REQUEST all charge devices within a 10 mile radius of the given location
            tenMileRadius = 'http://chargepoints.dft.gov.uk/api/retrieve/registry/lat/
    ' + str(latitude) + '/long/' + str(longitude) + '/dist/' + distance + '/format/json'
            print("okay1")

            # get response in JSON
            radius_response = requests.get(tenMileRadius).json() # error thrown here
            print("okay2")

            # use list comprehension to create a list of the coordinates
            radius_coordinates = [
            [float(device['ChargeDeviceLocation']['Latitude']),
             float(device['ChargeDeviceLocation']['Longitude'])] \
            for device in radius_response['ChargeDevice']]
            print(radius_coordinates)


            # pass variables
            geocode = 1
            chargepoints = 1
            routing = 0
            route_to = 0

            return render_template('index.html',latitude=latitude,longitude=longitude,geocode=geocode,chargepoints=chargepoints,radius_coordinates=radius_coordinates,routing=routing,route_to=route_to)

The request URL works fine, for example when I open - http://chargepoints.dft.gov.uk/api/retrieve/registry/lat/53.7948/long/-1.54655/dist/6/format/json - in the browser it displays JSON data. I have no idea why the error has begun to show when it was working before. Any ideas?

You must log in to answer this question.

Browse other questions tagged .