Flask not recognising two URL parameters

2019-03-03 10:54发布

I'm trying to send two parameters to a URL routed with Flask.

If I do:

curl -i http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell

Then my code which is:

@application.route('/api/journeys/count', methods=['GET'])
def journeys():
    print request.args
    startStationName = request.args.get('startStationName')
    endStationName = request.args.get('endStationName')

Should print a dict with startStationName and endStationName defined.

However, instead, only the first parameter seems to be received:

ImmutableMultiDict([('startStationName', u'Hansard Mews, Shepherds Bush')])

Anybody got any idea what I'm doing wrong? I have a feeling there must be some kind of stupid mistake or misunderstanding somewhere but I've been looking for an hour and can't find it.

1条回答
戒情不戒烟
2楼-- · 2019-03-03 11:06

Your shell interprets the & as a put the command in the background character. To prevent this, quote the whole URL:

curl -i "http://127.0.0.1:5000/api/journeys/count?startStationName=Hansard%20Mews,%20Shepherds%20Bush&endStationName=Farringdon%20Lane,%20Clerkenwell"
查看更多
登录 后发表回答