Search code examples
pythonflaskflask-restful

Error when passing parameter from url to method


I am using Flask for my webservice and when I try to access the following url

http://127.0.0.1:5000/2,3/5,6

I receive the following error:

return self.view_functions[rule.endpoint](**req.view_args)
TypeError: getDistance() got an unexpected keyword argument 'startCoord'

How can I fix this error?

Code:

@app.route("/<string:startCoord>/<string:endCoord>",methods=['GET'] )
def getDistance():
startLat, startLng = startCoord.split(',')
end1Lat, endLng = endCoord.split(',')

print("/api.openrouteservice.org/v2/directions/driving-car?api_key=" + config['EndPoint']['api_key'] + "&start=" + startLat + "," + startLng + "&end=" + end1Lat + "," + endLng)

Output:

['API_KEY']
<Section: API_KEY>

Solution

  • You are meant to define your route like this:

    @app.route("/<string:startCoord>/<string:endCoord>",methods=['GET'] )
    def getDistance(startCoord, endCoord):
        startLat, startLng = startCoord.split(',')
        end1Lat, endLng = endCoord.split(',')